1 回答

TA貢獻(xiàn)1817條經(jīng)驗(yàn) 獲得超14個贊
在特殊字符前使用反斜杠
var initialScript = `from django.utils.text import slugify
from django.utils.safestring import mark_safe
def generate_unique_slug(klass, field):
"""
return unique slug if origin slug is exist.
eg: \`foo-bar\` => \`foo-bar-1\`
:param \`klass\` is Class model.
:param \`field\` is specific field for title.
"""
origin_slug = slugify(field)
unique_slug = origin_slug
numb = 1
while klass.objects.filter(slug=unique_slug).exists():
unique_slug = '%s-%d' % (origin_slug, numb)
numb += 1
return unique_slug
brian='Hello life!'`
添加回答
舉報(bào)