Opened 14 years ago

Closed 11 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 Luke Plant, 14 years ago

Type: Bug

comment:2 by Luke Plant, 14 years ago

Severity: Normal

comment:3 by Julien Phalip, 14 years ago

Component: Core (Other)Documentation
Triage Stage: UnreviewedAccepted
Type: BugCleanup/optimization

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.

comment:4 by Aymeric Augustin, 13 years ago

UI/UX: unset

Change UI/UX from NULL to False.

comment:5 by Aymeric Augustin, 13 years ago

Easy pickings: unset

Change Easy pickings from NULL to False.

comment:6 by Tim Graham, 12 years ago

Summary: reverse does not work if quotation mark is used on a keyword argumentDocument 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 Tim Graham, 11 years ago

Resolution: needsinfo
Status: newclosed

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.

Note: See TracTickets for help on using tickets.
Back to Top