Django 看不到我的 url

Django not see my url

我得到 url 导致按日期过滤的对象列表,但由于某种原因我一直得到 404。在那个 404 URL 中代表...

url

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>[\w.@+-]+)/$ [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