当我阅读Django代码时,我经常在模型中看到所谓的“slug”。我不太确定这是什么,但我知道它与url有关。这个鼻涕虫什么时候该怎么用?
(我已在本术语表中阅读了它的定义。)
鼻涕虫 某物的缩写标签,只包含字母、数字、 下划线或连字符。它们通常用于url中。例如, 在一个典型的博客入口URL中: https://www.djangoproject.com/weblog/2008/apr/12/spring/最后一位 (弹簧)是鼻涕虫。
当我阅读Django代码时,我经常在模型中看到所谓的“slug”。我不太确定这是什么,但我知道它与url有关。这个鼻涕虫什么时候该怎么用?
(我已在本术语表中阅读了它的定义。)
鼻涕虫 某物的缩写标签,只包含字母、数字、 下划线或连字符。它们通常用于url中。例如, 在一个典型的博客入口URL中: https://www.djangoproject.com/weblog/2008/apr/12/spring/最后一位 (弹簧)是鼻涕虫。
当前回答
请允许我提供一些历史背景:
术语“弹头”与铸造金属铅有关,在这种情况下,印刷字体是由金属铅制成的。然后,每张纸的字体工厂都会定期重新熔化并在新的模具中重新铸造,因为经过多次打印后,它们会磨损。像我这样的学徒在那里开始了他们的职业生涯,并一路走到顶峰(不再)。
Typographs had to compose the text of an article in a backward manner with lead characters stacked in a wise. So at printing time the letters would be straight on the paper. All typographs could read the newspaper mirrored as fast as the printed one. Therefore the slugs, (like snails) also the slow stories (the last to be fixed) were many on the bench waiting, solely identified by their fist letters, mostly the whole title generally more readable. Some "hot" news were waiting there on the bench, for possible last minute correction, (Evening paper) before last assembly and definitive printing.
姜戈走出了劳伦斯杂志在堪萨斯州的办公室。那里可能还有一些印刷术语。A-django-enthusiast -&-friendly-old-slug-boy-from-France。
其他回答
请允许我提供一些历史背景:
术语“弹头”与铸造金属铅有关,在这种情况下,印刷字体是由金属铅制成的。然后,每张纸的字体工厂都会定期重新熔化并在新的模具中重新铸造,因为经过多次打印后,它们会磨损。像我这样的学徒在那里开始了他们的职业生涯,并一路走到顶峰(不再)。
Typographs had to compose the text of an article in a backward manner with lead characters stacked in a wise. So at printing time the letters would be straight on the paper. All typographs could read the newspaper mirrored as fast as the printed one. Therefore the slugs, (like snails) also the slow stories (the last to be fixed) were many on the bench waiting, solely identified by their fist letters, mostly the whole title generally more readable. Some "hot" news were waiting there on the bench, for possible last minute correction, (Evening paper) before last assembly and definitive printing.
姜戈走出了劳伦斯杂志在堪萨斯州的办公室。那里可能还有一些印刷术语。A-django-enthusiast -&-friendly-old-slug-boy-from-France。
从这里。
"鼻涕虫"是报纸上的术语,但是 这意味着这是最后一点 URL。例如,带有 标题,“一点关于Django” 成为“bit-about-django” 自动地(当然,你可以, 如果您不喜欢,可以轻松更改 自动生成的蛞蝓)。
简而言之,slug帮助摆脱那些丑陋的url与有效的url为例,在一个电子商务网站,而不是显示url为www.myecom.com/product/5432156,我可以显示它像www.myecom.com/product/iphone11与slug的帮助
段码是URL的一部分,它以易于阅读的形式标识网站上的特定页面。
例如,/building-your- first -django-site。
弹头只包含:
字母:a-z, a-z 数字:0-9 下划线:_ 连字符:-
也可以在django-admin中自动加载。在ModelAdmin添加:
prepopulated_fields = {'slug': ('title', )}
在这里:
class ArticleAdmin(admin.ModelAdmin):
list_display = ('title', 'slug')
search_fields = ('content', )
prepopulated_fields = {'slug': ('title', )}