Alexey Kostopravkin
Alexey Kostopravkin

Reputation: 29

Django not see my url

I got url that leads to list of objects flltred by date, but for some reason I got 404 all time. And in that 404 URL is represented...

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 message

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'] 

just dont get why this happening

Upvotes: 0

Views: 67

Answers (1)

karthikr
karthikr

Reputation: 99660

Your issue is with the regex pattern for capturing the date related named groups.

When you do this

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

[0-9] matches only 1 digit. What you need is, to capture more than one digits for date.

Something like this:

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

If you choose to be more specific,

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

You can get some more context on this here

Upvotes: 4

Related Questions