Django urlpatterns不匹配

时间:2012-07-25 20:37:41

标签: python django url-pattern

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

    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 个答案:

答案 0 :(得分:0)

我认为\d{4}只会匹配4位数字。试试\d{1,4}

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