Code

Opened 7 years ago

Closed 7 years ago

#3525 closed (fixed)

{% url path.to.view %} fails with multiple patterns for the same function

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

Description (last modified by mtredinnick)

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/"

Attachments (0)

Change History (5)

comment:1 Changed 7 years ago by Gary Wilson <gary.wilson@…>

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Design decision needed

comment:2 Changed 7 years ago by mtredinnick

  • Description modified (diff)
  • Owner changed from adrian to mtredinnick
  • Status changed from new to assigned

Yep. A bug.

comment:3 Changed 7 years ago by mtredinnick

  • Triage Stage changed from Design decision needed to Accepted

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 Changed 7 years ago by anonymous

  • Cc django@… added

comment:5 Changed 7 years ago by ubernostrum

  • Resolution set to fixed
  • Status changed from assigned to closed

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

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.