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

标签 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+)/$

我的根 url 配置是:

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

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

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

最佳答案

您当前的设置将匹配这样的 URL:

/post/post/1485/

使 posts/urls.py 看起来像:

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

关于python - Django URL 与任何 URL 配置都不匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11980110/

相关文章:

Java Map反模式?

delphi - 复杂的软件架构

spring-boot - 为什么我不应该在一个 Controller 类中调用多个服务?

python - python中 'set.intersection()'的算法是什么?

python - 正则表达式将 3 组 : 1st word, 最后一个单词和句子的其余部分

python - Django:过滤日期之间的数据 | DatetimeField 收到一个简单的日期时间

django - pip install dj-database-url 给出了权限被拒绝的错误

python - 在 Mac OS X (10.7) 上安装 graph-tool - 已经安装了 Boost,但不断出现此错误

python - Docker 中的应用程序不更新

python - 如何在pycharm中相应选择python版本?