Django没有看到我的网址

问题描述:

我得到的URL导致按日期列出的对象,但由于某种原因,我所有的时间都404。而在这404 URL表示...Django没有看到我的网址

网址

urlpatterns = patterns('', 
.... 
url(r'^castingListbydate/(?P<year>[0-9])/(?P<month>[0-9])/(?P<day>[0-9])/(?P<type>[0-9])/$', 'app.views.castingListbydate', name='castingListbydate'), 

404消息

Page not found (404) 
Request Method:  GET 
Request URL: http://localhost:50862/castingListbydate/2016/1/7/0 

Using the URLconf defined in Casting.urls, Django tried these URL patterns, in this order: 

    ^$ [name='home'] 
    ^$ [name='messages_redirect'] 
    ^inbox/$ [name='messages_inbox'] 
    ^outbox/$ [name='messages_outbox'] 
    ^compose/$ [name='messages_compose'] 
    ^compose/(?P<recipient>[\[email protected]+-]+)/$ [name='messages_compose_to'] 
    ^reply/(?P<message_id>[\d]+)/$ [name='messages_reply'] 
    ^view/(?P<message_id>[\d]+)/$ [name='messages_detail'] 
    ^delete/(?P<message_id>[\d]+)/$ [name='messages_delete'] 
    ^undelete/(?P<message_id>[\d]+)/$ [name='messages_undelete'] 
    ^trash/$ [name='messages_trash'] 
    ^contact$ [name='contact'] 
    ^about$ [name='about'] 
    ^rules$ [name='rules'] 
    ^typo_create$ [name='typo_create'] 
    ^castingCard/(?P<id>[0-9])/$ [name='castingCard'] 
    ^artistBase/(?P<actor>[0-9]{1})/(?P<dancer>[0-9]{1})/(?P<modl>[0-9]{1})/(?P<singer>[0-9]{1})/$ [name='artistBase'] 
    ^artistSearch$ [name='artistSearch'] 
    ^artistBases$ [name='artistBases'] 
    ^actorsBase$ [name='actorsBase'] 
    ^dancerBase$ [name='dancerBase'] 
    ^modelsBase$ [name='modelsBase'] 
    ^vocalBase$ [name='vocalBase'] 
    ^castingListbydate/(?P<year>[0-9])/(?P<month>[0-9])/(?P<day>[0-9])/(?P<type>[0-9])/$ [name='castingListbydate'] 

只是不明白为什么这种情况发生

你的问题是与正则表达式模式捕获日期相关的命名组。

当你做到这一点

(?P<year>[0-9])/(?P<month>[0-9])/(?P<day>[0-9])/(?P<type>[0-9]) 

[0-9]比赛只有1位数。你需要的是,为日期捕获多个数字。

事情是这样的:

(?P<year>[0-9]+)/(?P<month>[0-9]+)/(?P<day>[0-9]+)/(?P<type>[0-9]+) 

如果您选择更具体,

(?P<year>[0-9]{4})/(?P<month>[0-9]{1, 2})/(?P<day>[0-9]{1, 2})/(?P<type>[0-9]+) 

你可以得到一些更context on this here