2012-07-25 93 views
0

我一直在尝试一切,但我无法获得这些数字匹配。我在这里错过了什么吗?像非默认模块一样?Django urlpatterns不匹配

 
    Page not found (404) 
    Request Method: GET 
    Request URL: http://example.com/blog/1/1/1/ 
    Using the URLconf defined in blog.urls, Django tried these URL patterns, in this order: 
    ^blog/(?P\d{4})/(?P\d{2})/(?P\d{2})/$ 
    ^blog/(\d+)/(\d+)/(\d+)/$ 
    The current URL, , didn't match any of these. 

而且,我的urls.py文件:

from django.conf.urls import patterns, include, url             
import views                       
from views import hello_world, date_try, blog_test             

urlpatterns = patterns('',                   
    url(r'^blog/(?P<year>\d{4})/(?P<month>\d{2})/(?P<day>\d{2})/$', views.date_try),     
    url(r'^blog/(\d+)/(\d+)/(\d+)/$', 'date_try'),             
)                          
+1

是你的根urlconf,还是被另一个urlconf包含? – 2012-07-25 20:59:01

回答

0

我觉得 \d{4}只会完全匹配4位数。尝试 \d{1,4}

它看起来像Django认为你的URL是空的。你如何运行Django? this answer有用吗?

+1

'^ blog /(\ d +)/(\ d +)/(\ d +)/ $'应该与'blog/1/1/1 /' – 2012-07-25 20:58:11

+0

sam匹配,您的观察是正确的。谢谢。 – CDC 2012-07-30 02:01:22

+0

很高兴我能帮到你!如果这确实解决了你的问题,你能接受我的答案吗?接受答案有助于[堆栈溢出更好](http://stackoverflow.com/faq#howtoask)。 – 2012-07-30 18:44:59