#30995: Feature/docs: how should url converters decline to match for a named
route?
-------------------------------------+-------------------------------------
Reporter: Jack Cushman | Owner: nobody
Type: New feature | Status: new
Component: Core (URLs) | Version: 2.2
Severity: Normal | Resolution:
Keywords: reverse, urls, | Triage Stage:
converter | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Jack Cushman):
* status: closed => new
* resolution: invalid =>
Comment:
''Having multiple URLs with the same name is not supported.''
Hmm, I don't think that's right.
[https://docs.djangoproject.com/en/dev/topics/http/urls/#naming-url-
patterns According to the docs]: "You may also use the same name for
multiple URL patterns if they differ in their arguments. In addition to
the URL name, reverse() matches the number of arguments and the names of
the keyword arguments."
There's code in django.urls.resolvers specifically to support polymorphic
name resolution, which is why examples like this will work:
Resolution based on keywords:
{{{
path('export/baz/<int:baz>', index, name='export'), # {% url "export"
baz=1 %}
path('export/boo/<int:boo>', index, name='export'), # {% url "export"
boo=1 %}
}}}
Resolution based on values:
{{{
re_path(r'^import/foo/(\d+)$', index, name='import'), # {% url
"import" 123 %}
re_path(r'^import/bar/([a-z]+)$', index, name='import'), # {% url
"import" "abc" %}
}}}
It is strange for polymorphic name resolution to be supported in both of
those cases, but not in the case where one converter can successfully
convert the value and the other cannot. I filed this bug to address that
edge case.
--
Ticket URL: <https://code.djangoproject.com/ticket/30995#comment:2>
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 view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/066.35e20c79591b7b30ec80d8628fa735f6%40djangoproject.com.