How do I create a slug in Django?(如何在 Django 中创建 slug?)
问题描述
I am trying to create a SlugField
in Django.
I created this simple model:
I then do this:
I was expecting b-b-b-b
.
You will need to use the slugify function.
You can call slugify
automatically by overriding the save
method:
Be aware that the above will cause your URL to change when the q
field is edited, which can cause broken links. It may be preferable to generate the slug only once when you create a new object:
这篇关于如何在 Django 中创建 slug?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!