Opened 18 years ago
Last modified 14 years ago
#4311 closed
urlresolvers.resolve and friends should return the name they resolved to. — at Version 2
Reported by: | Owned by: | nobody | |
---|---|---|---|
Component: | Core (Other) | Version: | dev |
Severity: | Keywords: | ||
Cc: | Triage Stage: | Design decision needed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description (last modified by )
Now that urlresolvers.reverse and named URLPatterns are in place, I think it'd be good for resolve to return the name in addition to the callable and args/kwargs.
This would allow app-level branching depending on URL to be simpler.
As an example from a django-users list thread:
is_login = request.path in ( settings.LOGIN_REDIRECT_URL, settings.LOGIN_URL, settings.LOGOUT_URL) if ((not is_login) and ...
If urlresolvers.resolve() returned, (callable, args, kwargs, name) rather than (callable, args, kwargs), (where name is the name assigned in the URLPattern definition), you could have simpler code that inspected URL names and decided what to do with less muss.
if urlresolvers.resolve(url)[3].startswith('contrib.auth.urls.')
The 3 is icky and auth doesn't actually include an urls file, but you get the point. ;-)
Further, it'd be good if names were nested based on includes in a way that mirrors URLResolver includes so that the name of anything included by an app was prefixed by that app name.
For example:
urlpatterns = ( ('admin/', include('django.contrib.admin.urls') )
Assuming the admin urls definition was changed to include things like this:
('^([^/]+)/([^/]+)/$', 'django.contrib.admin.views.main.change_list', name='change_list'),
Then a request path resolving to the admin change list would include a return name of 'contrib.admin.urls.change_list'.
I imagine the advice that urlconf names be global-ish is just due to current implementation limitation. :)
http://www.djangoproject.com/documentation/url_dispatch/#naming-url-patterns
Change History (2)
comment:1 by , 18 years ago
Description: | modified (diff) |
---|
comment:2 by , 18 years ago
Description: | modified (diff) |
---|