Django 为应用定制化admin独立后台

定制后界面

Django 为应用定制化admin独立后台_第1张图片Django 为应用定制化admin独立后台_第2张图片

在应用目录下找到admin.py并进行编辑

from django.contrib.admin import AdminSite
from .models import Question,Choice

class PollsAdminSite(AdminSite):
    site_header="Admin-site-header"
    site_title="admin-site-title"
    index_title="admin-index-title"

polls_admin_site=PollsAdminSite(name='polls_admin')
polls_admin_site.register(Question)
polls_admin_site.register(Choice)

定制admin登录和导航标题

site_header="Admin-site-header"

定制admin页面标签Title

site_title="admin-site-title"

定制admin索引标题

index_title="admin-index-title"

定制admin管理入口URL

编辑项目目录中的urls.py

导入应用的admin,例如应用名为polls

from polls.admin import polls_admin_site

添加地址,例如地址为pollsadmin

path("pollsadmin/", polls_admin_site.urls)

from django.contrib import admin
from polls.admin import polls_admin_site
from django.urls import path,include

urlpatterns = [

    path("polls/",include("polls.urls")),
    path("pollsadmin/", polls_admin_site.urls),

    path("admin/", admin.site.urls),

]

你可能感兴趣的:(django,python)