#27367: Document behaviour when several urls have the same name
-------------------------------------+-------------------------------------
Reporter: Christoph Schindler | Owner: Robert
Type: | Roskam
Cleanup/optimization | Status: assigned
Component: Documentation | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Marten Kenbeek):
You can use multiple urls with the same name. These urls will be tried in
reverse order, so starting at the bottom of the list. All arguments passed
to `reverse()` must be used by the pattern to be considered valid. Default
arguments (passed as the `kwargs` parameter to `url()`) may be passed to
`reverse()` as well, but if they are passed, the values must match the
actual arguments to be considered a valid pattern. Consider these
patterns:
{{{
url(r'^spam/$', 'myapp.views.index', name='myview'), # 1
url(r'^spam/(?P<ham>[\w-]+)/$', 'myapp.views.detail', name='myview'),
# 2
url(r'^spam/(?P<ham>[\w-]+)/(?P<eggs>[\w-]+)/$', 'myapp.views.detail',
name='myview'), # 3
url(r'^spam/(?P<ham>[\w-]+)/$', 'myapp.views.detail', kwargs={'eggs':
'bar'} name='myview'), # 4
}}}
Both of these would successfully reverse pattern 4:
{{{
>>> reverse('myview', kwargs={'ham': 'foo'})
'/spam/foo/'
>>> reverse('myview', kwargs={'ham': 'foo', 'eggs': 'bar'})
'/spam/foo/'
}}}
However, this would not match pattern 4, as the value of `eggs` does not
match the original value of `eggs` passed to `url()`. Instead, it will
fall through and match pattern 3:
{{{
>>> reverse('myview', kwargs={'ham': 'foo', 'eggs': 'baz'})
'/spam/foo/baz/'
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/27367#comment:3>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/061.61dcc29160cca705136829d14a646134%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.