美文网首页
django-taggit 中文 Slug 解决方法

django-taggit 中文 Slug 解决方法

作者: 鱼儿的记忆 | 来源:发表于2019-06-23 15:58 被阅读0次

    django-taggit 中文 Slug

    当安装完 Taggit 后发现 tags Slug 中文不显示。在Template 中还报错。如何解决呢

    • 安装如下:

      pip install django-uuslug
      
    • 在App 目录下 生成cn_taggit.py

      from taggit.models import Tag, TaggedItem
      from uuslug import slugify
      
      class CnTag(Tag):
        class Meta:
          proxy = True
      
        def slugify(self, tag, i=None):
          return slugify(self.name)[:128]
      
      class CnTaggedItem(TaggedItem):
        class Meta:
          proxy = True
      
        @classmethod
        def tag_model(cls):
          return CnTag
      
    • 在 models.py中

      from .cn_taggit import CnTaggedItem
      
    tags = TaggableManager(blank=True, through=CnTaggedItem)
    
    django-taggit 中文 Slug 解决方法

    请关注微信 “coder2020”

    相关文章

      网友评论

          本文标题:django-taggit 中文 Slug 解决方法

          本文链接:https://www.haomeiwen.com/subject/rgziqctx.html