为什么我的 Django URL 调度程序不工作?
我真的很困惑为什么我的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你的正则表达式是错误的。
(?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]+)