Code

Opened 10 months ago

Last modified 3 months ago

#21132 assigned Bug

AdminSite cannot handle different namespace

Reported by: MarkusH Owned by: vajrasky
Component: contrib.admin Version: master
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Assume you have a custom admin inheriting from django.contrib.admin.sites.AdminSite and you want to run it with its own namespace:

# testproject/urls.py 
from django.conf.urls import patterns, include, url
from django.contrib.admin.sites import AdminSite

my_admin = AdminSite(name='name', app_name='app_name')

urlpatterns = patterns('',
    url(r'^admin/', include(my_admin.urls)),
)

This is going to fail with the following error:

Traceback (most recent call last):
  File "/home/markus/.venvs/django-namespace-test/lib/python3.3/site-packages/django/core/urlresolvers.py", line 482, in reverse
    extra, resolver = resolver.namespace_dict[ns]
KeyError: 'admin'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/markus/.venvs/django-namespace-test/lib/python3.3/site-packages/django/core/handlers/base.py", line 115, in get_response
    response = callback(request, *callback_args, **callback_kwargs)
  File "/home/markus/.venvs/django-namespace-test/lib/python3.3/site-packages/django/contrib/admin/sites.py", line 219, in wrapper
    return self.admin_view(view, cacheable)(*args, **kwargs)
  File "/home/markus/.venvs/django-namespace-test/lib/python3.3/site-packages/django/utils/decorators.py", line 91, in _wrapped_view
    response = view_func(request, *args, **kwargs)
  File "/home/markus/.venvs/django-namespace-test/lib/python3.3/site-packages/django/views/decorators/cache.py", line 89, in _wrapped_view_func
    response = view_func(request, *args, **kwargs)
  File "/home/markus/.venvs/django-namespace-test/lib/python3.3/site-packages/django/contrib/admin/sites.py", line 198, in inner
    current_app=self.name):
  File "/home/markus/.venvs/django-namespace-test/lib/python3.3/site-packages/django/core/urlresolvers.py", line 492, in reverse
    key)
django.core.urlresolvers.NoReverseMatch: 'admin' is not a registered namespace

Attachments (0)

Change History (4)

comment:1 follow-up: Changed 10 months ago by apollo13

  • Component changed from Uncategorized to contrib.admin
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted
  • Type changed from Uncategorized to Bug
  • Version changed from 1.5 to master

The whole admin is currently built on the idea that the app is named admin, I think we should just deprecate the app_name argument.

comment:2 Changed 8 months ago by vajrasky

  • Has patch set
  • Owner changed from nobody to vajrasky
  • Status changed from new to assigned

This ticket is quite big (at least for me). This PR is the first step to fix this issue. https://github.com/django/django/pull/1845

There are more to be done. You can check by:
$ grep -R "admin:" *

comment:3 in reply to: ↑ 1 Changed 8 months ago by glarrain

Replying to apollo13:

The whole admin is currently built on the idea that the app is named admin, I think we should just deprecate the app_name argument.

I disagree. I think we should fix it. Hardcoded admin strings all around are, IMO, a very bad idea.

On the other hand, I'm not really an expert in app and URL namespacing so take my comment with a grain of salt.

PS: this topic is currently discussed in the mailing list https://groups.google.com/forum/#!topic/django-developers/pc5A3qrvITQ

comment:4 Changed 3 months ago by vzima

+1 for removal of app_name argument. It mostly just confuses developers since it can not be changed to anything else, see #19002, #19554, #22418.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as assigned
The owner will be changed from vajrasky to anonymous. Next status will be 'assigned'
The ticket will be disowned. Next status will be 'new'
as The resolution will be set. Next status will be 'closed'
Author


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

 
Note: See TracTickets for help on using tickets.