#7522 closed (invalid)
django.core.urlresolvers.reverse can't accept complex regular expression.
Reported by: | bear330 | Owned by: | nobody |
---|---|---|---|
Component: | Core (Other) | Version: | dev |
Severity: | Keywords: | ||
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
I have a url pattern like this:
url(r'^(?P<strategy>\w+)/(?P<scale>(hours|days))/(?P<duration>[1-365]+)$', 'views.index', name='indexDuration')
It will fail when I call:
reverse('indexDuration', args=['trace', 'hours', 24])
the exception raised:
... File "C:\Program Files\Python25\Lib\site-packages\django\core\urlresolvers.py", line 88, in reverse_helper result = re.sub(r'\(([^)]+)\)', MatchChecker(args, kwargs), regex.pattern) ... error: unbalanced parenthesis
This is related to #6934, but it also raise exception when I change the url to:
url(r'^(?P<strategy>\w+)/(?P<scale>hours)/(?P<duration>[1-365]+)$', 'views.index', name='indexDuration')
>>> reverse('indexDuration', args=['trace', 'hours', 24]) ... File "C:\Program Files\Python25\Lib\site-packages\django\core\urlresolvers.py", line 88, in reverse_helper result = re.sub(r'\(([^)]+)\)', MatchChecker(args, kwargs), regex.pattern) ... NoReverseMatch: Value 24 didn't match regular expression '[1-365]+'
This is a related but other situation to cause reverse raise exception.
Change History (2)
follow-up: 2 comment:1 by , 17 years ago
Resolution: | → invalid |
---|---|
Status: | new → closed |
comment:2 by , 17 years ago
Oh, I am sorry about getting confused with regular expression. :)
Thank you.
Note:
See TracTickets
for help on using tickets.
Remove unneeded parenthesis around (hours|days) and rewrite your ![1-365] part as it is completely broken (it matches only 1,2,3,5,6 digits). Better use \d macros and check bounds in the view.
works good.