我有模型Author有字段名字、姓氏。我想添加另一个字段'slug'它将包含字段串联的段。但是,这些字段包含非英语字符,我需要一个英语符号来创建链接模板“本地主机/作者/str::slug”我该如何实施?
要解决这个问题,您可以使用unidecode
and slugify
.
你应该安装它pip install unidecode
from unidecode import unidecode
from django.template import defaultfilters
slug = defaultfilters.slugify(unidecode(input_text))
example:
import unidecode
a = unidecode.unidecode('привет')
the answer will be ('privet') #this is just an example in russian.
and after that you can apply slugify
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)