是否可以更改django管理站点中的数据库名称?
就像我如何更改以下内容一样:
admin.site.site_header =“管理员” admin.site.site_title =“管理员” admin.site.index_title =“管理”
发布于 2022-08-20 04:04:52
有两个选项,您可以手动完成,也可以通过外部python库进行操作。
手动
是通过创建自定义AdminSite实现的。
admin.py
from django.contrib.admin import AdminSite
from django.utils.translation import ugettext_lazy
class MyAdminSite(AdminSite):
# Text to put at the end of each page's <title>.
site_title = ugettext_lazy('My site admin')
# Text to put in each page's <h1> (and above login form).
site_header = ugettext_lazy('My administration')
# Text to put at the top of the admin index page.
index_title = ugettext_lazy('Site administration')
admin_site = MyAdminSite()
urls.py
from django.conf.urls import patterns, include
from myproject.admin import admin_site
urlpatterns = patterns('',
(r'^admin/', include(admin_site.urls)),
)
通过使用python包
您可以使用称为django-管理-界面的python包。
pip install django-admin-interface
您需要将它导入您的settings.py
INSTALLED_APPS = (
#...
"admin_interface",
"flat_responsive", # only if django version < 2.0
"flat", # only if django version < 1.9
"colorfield",
#...
"django.contrib.admin",
#...
)
# only if django version >= 3.0
X_FRAME_OPTIONS = "SAMEORIGIN"
SILENCED_SYSTEM_CHECKS = ["security.W019"]
安装之后,您可以从管理面板中的“主题”菜单中自定义管理面板
您可以通过在verbose_name
下添加app.py来更改应用程序名。
from django.apps import AppConfig
class PharmacyConfig(AppConfig):
name = 'pharmacy'
verbose_name = 'Your Home Page'
https://stackoverflow.com/questions/73426486
复制