Opened 17 years ago

Closed 17 years ago

#3525 closed (fixed)

{% url %} fails with multiple patterns for the same function

Reported by: omat@… Owned by: nobody
Component: Template system Version: dev
Severity: Keywords: url, template
Cc: django@… Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Malcolm Tredinnick)

If there are multiple patterns matching the same view function, it seems like, only the first match is considered.

Lets say a function has an optional "id" parameter which defaults to None and below is the patterns pointing that function.

(r'^(?P<slug>[-\w]+)/$', views.myfunc),

(r'^(?P<slug>[-\w]+)/(?P<id>\d+)/$', views.myfunc),

In that case,

{% url views.myfunc slug=something,id=someint %}

fails to match anything, where we can expect it to match the second
pattern and return "/something/someint/"

Change History (5)

comment:1 by Gary Wilson <gary.wilson@…>, 17 years ago

Triage Stage: UnreviewedDesign decision needed

comment:2 by Malcolm Tredinnick, 17 years ago

Description: modified (diff)
Owner: changed from Adrian Holovaty to Malcolm Tredinnick
Status: newassigned

Yep. A bug.

comment:3 by Malcolm Tredinnick, 17 years ago

Triage Stage: Design decision neededAccepted

oops... clicked the wrong box. Meant to change it to "accepted" not take assignment. Ah well ... I'm not working on this one, folks, so somebody else should feel free. :-)

comment:4 by anonymous, 17 years ago

Cc: django@… added

comment:5 by James Bennett, 17 years ago

Resolution: fixed
Status: assignedclosed

This was fixed by the introduction of named URL patterns, which provide a way to differentiate multiple patterns using the same view function.

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