为什么我的 Django URL 调度程序不工作?

发布于 2024-11-17 05:21:55 字数 836 浏览 1 评论 0原文

我真的很困惑为什么我的 URL 调度程序与这个 url 不匹配

http://127.0.0.1:8000/2011/jun/26/third-entry/

这就是我的主 url 调度程序的样子

urlpatterns = patterns('',
    (r'^admin/', include(admin.site.urls)),
    (r'^blog/', include('djangoblog.blog.urls')),
)

在我的博客文件夹中我有另一个 url 调度程序

urlpatterns = patterns('django.views.generic.date_based',
    #regex is passed to object_detail which is the name of the generic view that will pull out a single entry
    (r'^(?P<year>d{4})/(?P<month>[a-z]{3})/(?P<day>w{1,2})/(?P<slug>[-w]+)/$', 'object_detail', dict(info_dict, slug_field='slug',template_name='blog/detail.html')),
)

我也尝试过这个 url 但没有运气

http://127.0.0.1:8000/blog/2011/jun/26/third-entry/

我一定错过了一些非常简单的东西...

I'm really confused as to why my URL dispatcher is not matching this url

http://127.0.0.1:8000/2011/jun/26/third-entry/

This is what my main url dispatcher looks like

urlpatterns = patterns('',
    (r'^admin/', include(admin.site.urls)),
    (r'^blog/', include('djangoblog.blog.urls')),
)

And inside my blog folder I have another url dispatcher

urlpatterns = patterns('django.views.generic.date_based',
    #regex is passed to object_detail which is the name of the generic view that will pull out a single entry
    (r'^(?P<year>d{4})/(?P<month>[a-z]{3})/(?P<day>w{1,2})/(?P<slug>[-w]+)/

I also tried this url with no luck

http://127.0.0.1:8000/blog/2011/jun/26/third-entry/

I must be missing something really simple...

, 'object_detail', dict(info_dict, slug_field='slug',template_name='blog/detail.html')), )

I also tried this url with no luck

I must be missing something really simple...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

鸠魁 2024-11-24 05:21:55

你的正则表达式是错误的。

(?Pd{4}) 应为 (?P\d{4})

这同样适用于 URI 的其他部分:

  • (?P\d{1,2})
  • (?P[-\w]+)

Your regexp is wrong.

(?P<year>d{4}) should be (?P<year>\d{4})

The same applies to the other parts of the URI:

  • (?P<day>\d{1,2})
  • (?P<slug>[-\w]+)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文