#34494 closed Uncategorized (invalid)

This is suggestion about customizing AdminSite documents

Reported by: jianghan Owned by: nobody
Component: Documentation Version: 4.2
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 was using customizing adminsite and admindoc, I encountered an error message:

Reverse for 'app_list' with keyword arguments '{'app_label': 'auth'}' not found.

I wrote a custom adminsite according to the document code:

# admin.py
class MyAdminSite(admin.AdminSite):
    site_header = "Django4 Demo"

admin_site = MyAdminSite(name="myadmin")

# urls.py
urlpatterns = [
    path('admin/doc/', include('django.contrib.admindocs.urls')),
    path("admin/", admin_site.urls),
]

# settings.py
INSTALLED_APPS = [
    "django.contrib.admindocs",
    # "django.contrib.admin",
    "django4demo.apps.MyAdminConfig",
    ...
]

At the same time, I also installed admindoc.
After starting, click on "Document" on the page and the above error will appear.

Upon investigation, it was found that admindoc was using "admin. site" object from "django. contrib import admin".
And the route registration uses a custom "admin_site" object.
When "resolve(auth)",the route cannot be found, Because there is no under the custom "admin_site.urls".

When I replaced all "admin_site" object with native "admin.site" object, the problem was resolved.

Suggest adding relevant comments on the adminsite document to prevent others from falling into the trap.

thanks.

Change History (2)

comment:1 by jianghan, 17 months ago

Summary: This is questions about customizing AdminSite documentsThis is suggestion about customizing AdminSite documents

comment:2 by Mariusz Felisiak, 17 months ago

Resolution: invalid
Status: newclosed

If you want to use a custom admin site with admindocs you should still point urls from admin.site.urls:

from django.contrib import admin

urlpatterns = [
    path('admin/doc/', include('django.contrib.admindocs.urls')),
    path("admin/", admin.site.urls),
]

Django will properly resolve admin.site to your custom AdminSite.

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