urlresolvers.resolve and friends should return the name they resolved to.
|Reported by:||Owned by:||nobody|
|Cc:||Triage Stage:||Design decision needed|
|Has patch:||no||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||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.
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.
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 'django.contrib.admin.urls.change_list'.
I imagine the advice that urlconf names be global-ish is just due to current implementation limitation. :)