Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/295.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/278.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在网站的python django中的文章中放置标记_Python_Django_Web - Fatal编程技术网

如何在网站的python django中的文章中放置标记

如何在网站的python django中的文章中放置标记,python,django,web,Python,Django,Web,我的客户希望我建立一个文章发布网站,让用户登录并撰写文章。在文章中,他必须放置标签,其他用户可以使用这些标签进行搜索。问题是我不知道如何在视图中放置标记。还有html 我的视图文件是: 任何人都可以帮助我进行样本编码吗?有一个简单的第三方应用程序可以帮助您进行标记。它被称为django-taggit,您可以找到如何在its中轻松设置它,或者按照下面的步骤进行设置 基本上,您需要使用pip install django_taggit安装它,将它添加到您的INSTALLED_APPS中,并将管理器

我的客户希望我建立一个文章发布网站,让用户登录并撰写文章。在文章中,他必须放置标签,其他用户可以使用这些标签进行搜索。问题是我不知道如何在视图中放置标记。还有html

我的视图文件是:


任何人都可以帮助我进行样本编码吗?

有一个简单的第三方应用程序可以帮助您进行标记。它被称为django-taggit,您可以找到如何在its中轻松设置它,或者按照下面的步骤进行设置

基本上,您需要使用
pip install django_taggit安装它,将它添加到您的
INSTALLED_APPS
中,并将管理器添加到所需的模型中,例如:

from taggit.managers import TaggableManager

class Post(models.Model): 
    # ...
    tags = TaggableManager()
然后只需使用
python manage.py makemigrations post
python manage.py migrate
为模型更改创建一个迁移
现在,您可以使用简单的命令添加、删除或列出标记:

post.tags.add('tag1', 'tag2', 'tag3') # add tags
post.tags.remove('tag1') # remove tags
post.tags.all() # list tags