Opened 14 years ago
Closed 10 years ago
#15723 closed Cleanup/optimization (needsinfo)
Document limitations of reverse
Reported by: | zeroos | Owned by: | nobody |
---|---|---|---|
Component: | Documentation | Version: | dev |
Severity: | Normal | Keywords: | reverse regexp |
Cc: | Triage Stage: | Accepted | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
In urls.py I have the following line:
... (r'^json/calendar/((?P<course>[\d,]+)/)?$', json.calendar_block), ...
When I try to reverse this url this way:
reverse(json.calendar_block, kwargs={'course': 1})
I get an error saying that it cannot reverse this.
When I change the line in urls.py to:
... (r'^json/calendar/(?P<course>[\d,]+)/$', json.calendar_block), ...
everything works great.
I would assume that it is not a bug, but it worked before and suddenly, after pulling the newest Django release from svn it stopped.
Change History (7)
comment:1 by , 14 years ago
Type: | → Bug |
---|
comment:2 by , 14 years ago
Severity: | → Normal |
---|
comment:3 by , 14 years ago
Component: | Core (Other) → Documentation |
---|---|
Triage Stage: | Unreviewed → Accepted |
Type: | Bug → Cleanup/optimization |
comment:6 by , 12 years ago
Summary: | reverse does not work if quotation mark is used on a keyword argument → Document limitations of reverse |
---|
I am not sure what to add here as far as docs go. The code for reverse doesn't look too simple to me, and I am not sure how much detail we want to go into about how it works. Maybe the fact that nested groupings aren't supported? I haven't confirmed that to be the case, it's just a guess based on the example that doesn't work.
comment:7 by , 10 years ago
Resolution: | → needsinfo |
---|---|
Status: | new → closed |
In the doc we have: "The main restriction at the moment is that the pattern cannot contain alternative choices using the vertical bar ("|") character." I am closing this as needsinfo. If someone wants to do research and propose a patch, then please reopen with details.
The
reverse()
function does have some limitations, as stated in the doc (http://docs.djangoproject.com/en/dev/topics/http/urls/#reverse): "The reverse() function can reverse a large variety of regular expression patterns for URLs, but not every possible one". I think this is the case here. The documentation can be improved though, to reflect all (or at least the most common) limitations.