![](/img/trans.png)
[英]How to remove element tags from results, Web Scraping Articles with Python
[英]how to put tags in articles in python django in website
有一個簡單的第三方應用程序可以幫助您進行標記。 它被稱為django-taggit ,您可以在它的文檔頁面或按照本教程視頻找到如何輕松設置它。
基本上,您需要使用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
為您的模型更改創建python manage.py migrate
。
現在您可以使用簡單的命令添加、刪除或列出標簽:
post.tags.add('tag1', 'tag2', 'tag3') # add tags
post.tags.remove('tag1') # remove tags
post.tags.all() # list tags
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.