我的网址是这样的...

/eng/blog/site-news/


出现的错误看起来像这样...

^admin/
^(?P<page_lang>\w+)/blog/
^(?P<page_lang>\w+)/blog/
^(?P<page_lang>\w+)/blog/
^$
^(?P<category>\w+)/$
^(?P<category>\w+)/post/(?P<post_title>\w+)/$


我以前做过这个,从来没有遇到过这个问题,它一定很小,我没看到

urls.py#1

url(r'^admin/', include(admin.site.urls)),
url(r'^(?P<page_lang>\w+)/blog/', include('blog.urls')),
url(r'^blog/', include('blog.urls')),
url(r'^comments/', include('django_comments.urls')),
url(r'^', include('main.urls')),


urls.py#2

url(r'^$', 'blog.views.main_page'),
url(r'^(?P<category>\w+)/$', 'blog.views.category_page'),
url(r'^(?P<category>\w+)/post/(?P<post_title>\w+)/$', 'blog.views.post_page'),

最佳答案

\w匹配数字,字母和_;您需要包含-

^(?P<category>\w+)/post/(?P<post_title>[-\w]+)/$

关于python - 坚持为什么django找不到此URL?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/34348307/

10-16 02:48