1. 重写AdminConfig类
# myapp/apps.py
from django.apps import AppConfig
from django.contrib.admin.apps import AdminConfig
class MyAdminConfig(AdminConfig):
default_site ='myadmin.admin.MyAdminSite'
2. 使用 'myadmin.apps.MyAdminConfig' 代替 'django.contrib.admin'
# settings.py
INSTALLED_APPS = [# 'django.contrib.admin.apps.SimpleAdminConfig',
'myadmin.apps.MyAdminConfig', # replaces 'django.contrib.admin'
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'myadmin'
]
3. 重写AdminSite类
from django.contrib import admin
# Register your models here.
from django.contrib import admin
class MyAdminSite(admin.AdminSite):
...
runserver后,自定义站点完成