Django Url, Slug for Detail Page

a 夏天 提交于 2019-11-28 20:50:41

The urls are the problem, the first one will match everything (/blog/, /blog/test/, /blog/awdlawdjaawld), you need the dollar sign $ at the end of it to only match /blog/.

url(r'^blog/$', 'myapp.views.blog', name='blog'),
url(r'^blog/(?P<slug>[\w-]+)/$', 'myapp.views.blog_detail', name='blog_detail'),

The above should work correctly.

This is a good reference for Regular Expressions

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!