Django Admin Plus
AdminPlus is a Django admin panel extension that allows you to add custom views not tied to models, extending the built-in admin without replacing it entirely. It supports Django versions 3.0+ and Python 3.7+. While the last official PyPI release was in 2016 (v0.6), the project is actively maintained with CI/CD testing against recent Django and Python versions.
Warnings
- breaking Replacing `django.contrib.admin.site` is mandatory for `django-adminplus` to function. If you have other packages or custom code that relies on directly manipulating `django.contrib.admin.site` after it's been instantiated, this replacement might cause conflicts or unexpected behavior.
- gotcha Failure to correctly configure `INSTALLED_APPS` by replacing `'django.contrib.admin'` with `'django.contrib.admin.apps.SimpleAdminConfig'` and including `'adminplus'` can lead to custom views not appearing or the default Django admin overriding `django-adminplus` functionality.
- gotcha While `django-adminplus` version 0.6 is officially old (2016), its GitHub repository shows active CI testing against recent Django (3.2, 4.x, 5.0) and Python (3.8-3.12) versions. However, significant future changes in Django's internal admin structure could introduce compatibility issues not yet reflected in a new release.
Install
-
pip install django-adminplus
Imports
- AdminSitePlus
from adminplus.sites import AdminSitePlus
- admin.site.register_view
admin.site.register_view('somepath', view=my_view, name='My View Name')
Quickstart
import os
import django
from django.conf import settings
from django.urls import path, include
from django.contrib import admin
from adminplus.sites import AdminSitePlus
from django.http import HttpResponse
settings.configure(
DEBUG=True,
SECRET_KEY=os.environ.get('DJANGO_SECRET_KEY', 'insecure-dev-key'),
ROOT_URLCONF=__name__,
INSTALLED_APPS=[
'django.contrib.admin.apps.SimpleAdminConfig', # Replace default admin config
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'adminplus',
],
TEMPLATES=[
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
],
MIDDLEWARE_CLASSES=[
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
],
DATABASES={
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': ':memory:',
}
},
STATIC_URL='/static/',
)
django.setup()
# 1. Replace the default admin.site with AdminSitePlus
admin.site = AdminSitePlus()
admin.autodiscover()
# 2. Define your custom view
def my_custom_admin_view(request):
return HttpResponse("Hello from a custom admin view!")
# 3. Register the custom view
admin.site.register_view('my-path', view=my_custom_admin_view, name='My Custom View')
# Include the admin URLs
urlpatterns = [
path('admin/', admin.site.urls),
]
if __name__ == '__main__':
# This block is for demonstration only and assumes a Django project setup
# In a real project, you would run `python manage.py runserver`
print("Django Admin Plus quickstart configured.")
print("To run, you'd typically have this in your project's urls.py and settings.py.")
print("Access custom view at: /admin/my-path/")