Django URL与任何URL配置都不匹配

时间:2012-08-16 02:55:09

标签: python django design-patterns django-urls

错误消息是:

Using the URLconf defined in Blog.urls,
Django tried these URL patterns, in this order:

^admin/doc/
^admin/
^post/ ^post/(?P<post_id>\d+)/$

The current URL, post/1458/, didn't match any of these.

为什么呢?我认为post/1485/匹配^post/(?P<post_id>\d+)/$

我的根网址配置为:

urlpatterns = patterns('',
    ...
    url(r'^post/', include('posts.urls')),
)

然后,我的posts/urls.py是:

urlpatterns = patterns('',
    ...
    url(r'^post/(?P<post_id>\d+)/$', 'post.views.post_page'),
)

1 个答案:

答案 0 :(得分:8)

您当前的设置会匹配以下网址:

/post/post/1485/

posts/urls.py看起来像:

urlpatterns = patterns('',
    ...
    url(r'^(?P<post_id>\d+)/$', 'post.views.post_page'),
)