Reputation: 551
I've been looking at this now for hours and cannot seem to work out why it's not working. I'm trying to setup a regex to allow the following URL:
/news/monthly/2015/July/
Here is the URLConf setting:
url(r'^news/monthly/(?P<year>\d)/(?P<month>\w+)/$', 'Bolton_GC.News.views.monthlynews', name='monthlynews')
Can anyone spot the mistake because I'm missing something.
Thanks in advance.
Wayne
Upvotes: 1
Views: 39
Reputation: 626950
Use a +
quantifier with \d
(without it, only 1 digit is matched):
r'^news/monthly/(?P<year>\d+)/(?P<month>\w+)/$'
^
See demo
See Repetition with Star and Plus article for more details about +
quantifier:
The plus tells the engine to attempt to match the preceding token once or more.
Upvotes: 1
Reputation: 508
In the examples, the number is either given with (?P<year>[0-9]{4})
or with \d+ as in :
url(r'^news/monthly/(?P<year>\d+)/(?P<month>\w+)/$', 'Bolton_GC.News.views.monthlynews', name='monthlynews')
Hope it helped!
Upvotes: 2