じゅういち、添加标签功能

利用django-taggit模块,主要提供了一个Tag模型和一个管理器。
源代码

1. 安装

pip install django_taggit

2. 打开mysite项目的settings.py文件

INSTALLED_APPS = [
    # ...
    'blog.apps.BlogConfig',
    'taggit',
]

3. 打开blog应用程序的models.py文件

from taggit.managers import TaggableManager

class Post(models.Model):
    # ...
    tags = TaggableManager()

4. 生成迁移

python manage.py makemigrations blog
python manage.py migrate

5.

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。