Opened 11 years ago

Closed 11 years ago

#21131 closed Bug (invalid)

Admin URL patterns are not aware of the app_namespace

Reported by: Markus Holtermann Owned by: Florian Apolloner
Component: contrib.admin Version: 1.5
Severity: Normal Keywords:
Cc: info@… Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Given these files:

# testapp/views.py 
from django.core.urlresolvers import reverse
from django.http import HttpResponse

def testview(request):
    rev = reverse('admin:testview', current_app='something')
    return HttpResponse('Some Text %s' % rev)
# testapp/urls.py 
from django.conf.urls import patterns, url

urlpatterns = patterns('',
   url(r'^', 'testapp.views.testview', name='testview')
)
# testproject/urls.py 
from django.conf.urls import patterns, include, url
from django.contrib import admin
admin.autodiscover()

urlpatterns = patterns('',
    url(r'^admin/', include(admin.site.urls)),
    url(r'^foo/', include('testapp.urls', namespace='admin', app_name='something')),
)

I'd expect that the view testapp.views.testview is still available when resolving the 'admin:testview' with the current_app set explicitly. Instead I'm greeted with a NoReverseMatch at /foo/ error:

Traceback:
File "/home/markus/.venvs/django-namespace-test/lib/python3.3/site-packages/django/core/handlers/base.py" in get_response
  115.                         response = callback(request, *callback_args, **callback_kwargs)
File "/home/markus/Coding/django-namespace-test/testapp/views.py" in testview
  6.     rev = reverse('admin:testview', current_app='something')
File "/home/markus/.venvs/django-namespace-test/lib/python3.3/site-packages/django/core/urlresolvers.py" in reverse
  496.     return iri_to_uri(resolver._reverse_with_prefix(view, prefix, *args, **kwargs))
File "/home/markus/.venvs/django-namespace-test/lib/python3.3/site-packages/django/core/urlresolvers.py" in _reverse_with_prefix
  416.                 "arguments '%s' not found." % (lookup_view_s, args, kwargs))

Exception Type: NoReverseMatch at /foo/
Exception Value: Reverse for 'testview' with arguments '()' and keyword arguments '{}' not found.

Changing the order of the of the patterns in the ROOTURL_CONF makes the admin inaccessible:

Traceback:
File "/home/markus/.venvs/django-namespace-test/lib/python3.3/site-packages/django/core/handlers/base.py" in get_response
  115.                         response = callback(request, *callback_args, **callback_kwargs)
File "/home/markus/.venvs/django-namespace-test/lib/python3.3/site-packages/django/contrib/admin/sites.py" in wrapper
  219.                 return self.admin_view(view, cacheable)(*args, **kwargs)
File "/home/markus/.venvs/django-namespace-test/lib/python3.3/site-packages/django/utils/decorators.py" in _wrapped_view
  91.                     response = view_func(request, *args, **kwargs)
File "/home/markus/.venvs/django-namespace-test/lib/python3.3/site-packages/django/views/decorators/cache.py" in _wrapped_view_func
  89.         response = view_func(request, *args, **kwargs)
File "/home/markus/.venvs/django-namespace-test/lib/python3.3/site-packages/django/contrib/admin/sites.py" in inner
  198.                                            current_app=self.name):
File "/home/markus/.venvs/django-namespace-test/lib/python3.3/site-packages/django/core/urlresolvers.py" in reverse
  496.     return iri_to_uri(resolver._reverse_with_prefix(view, prefix, *args, **kwargs))
File "/home/markus/.venvs/django-namespace-test/lib/python3.3/site-packages/django/core/urlresolvers.py" in _reverse_with_prefix
  416.                 "arguments '%s' not found." % (lookup_view_s, args, kwargs))

Exception Type: NoReverseMatch at /admin/
Exception Value: Reverse for 'logout' with arguments '()' and keyword arguments '{}' not found.

Change History (4)

comment:1 by Markus Holtermann, 11 years ago

Cc: info@… added
Triage Stage: UnreviewedAccepted

I talked to apollo13 about this and therefore mark it as accepted.

comment:2 by Florian Apolloner, 11 years ago

Triage Stage: AcceptedUnreviewed

Um, MarkusH and I were talking about something slightly different, resetting to unreviewed.

comment:3 by Tim Graham, 11 years ago

Duplicate of #17914?

comment:4 by Markus Holtermann, 11 years ago

Resolution: invalid
Status: newclosed

Ok, I misread the docs. In the ROOTURL_CONF it must be

url(r'^foo/', include('testapp.urls', namespace='something', app_name='admin')),

to make it work.

Note: See TracTickets for help on using tickets.
Back to Top