Opened 9 years ago
Closed 9 years ago
#25035 closed Bug (duplicate)
urlresolvers.reverse doesn't resolve a namespaced URL when passed a callable
Reported by: | Adam Brenecki | Owned by: | nobody |
---|---|---|---|
Component: | Core (URLs) | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
When I pass a view callable to django.core.urlresolvers.reverse
, it resolves correctly if the callable is in the top-level urlpatterns
, or one in a urlpatterns
that's been include
d without a namespace, but not one that's been include
d with a namespace.
I've noticed this behaviour in 1.7 and in the current HEAD of master (as of 736fb1838cc25f5faf57cd2a4f6b6ab32ff9aadc).
Here's a minimal example (all files not listed are as generated by startproject
/startapp
):
testproj/urls.py
from django.conf.urls import url, include from django.contrib import admin import testapp.urls urlpatterns = [ url(r'^admin/', admin.site.urls), url(r'^testapp/', include(testapp.urls, namespace='testapp')), ]
testapp/urls.py
from django.conf.urls import url, include from django.contrib import admin from . import views urlpatterns = [ url(r'^myview', views.test), ]
testapp/views.py
from django.shortcuts import render # Create your views here. def test(): pass
Which results in this:
> python manage.py shell Python 2.7.6 (default, Jun 22 2015, 17:58:13) [GCC 4.8.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. (InteractiveConsole) >>> from django.core.urlresolvers import reverse >>> from testapp.views import test >>> reverse(test) Traceback (most recent call last): File "<console>", line 1, in <module> File "/home/abrenecki/django/django/core/urlresolvers.py", line 602, in reverse return force_text(iri_to_uri(resolver._reverse_with_prefix(view, prefix, *args, **kwargs))) File "/home/abrenecki/django/django/core/urlresolvers.py", line 510, in _reverse_with_prefix (lookup_view_s, args, kwargs, len(patterns), patterns)) NoReverseMatch: Reverse for 'testapp.views.test' with arguments '()' and keyword arguments '{}' not found. 0 pattern(s) tried: [] >>> exit()
If I remove the namespace, everything works as expected.
Change History (1)
comment:1 by , 9 years ago
Component: | Uncategorized → Core (URLs) |
---|---|
Resolution: | → duplicate |
Status: | new → closed |
Type: | Uncategorized → Bug |
Duplicate of #17914