Code

#21131 closed Bug (invalid)

Admin URL patterns are not aware of the app_namespace

Reported by: MarkusH Owned by: apollo13
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.

Attachments (0)

Change History (4)

comment:1 Changed 10 months ago by MarkusH

  • Cc info@… added
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

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

comment:2 Changed 10 months ago by apollo13

  • Triage Stage changed from Accepted to Unreviewed

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

comment:3 Changed 10 months ago by timo

Duplicate of #17914?

comment:4 Changed 10 months ago by MarkusH

  • Resolution set to invalid
  • Status changed from new to closed

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.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.