如何更改Django admin头中的“Django administration”文本?
“自定义管理”文档中似乎没有涉及到这一点。
如何更改Django admin头中的“Django administration”文本?
“自定义管理”文档中似乎没有涉及到这一点。
当前回答
对于Django 2.1.1,在urls.py中添加以下行
from django.contrib import admin
# Admin Site Config
admin.sites.AdminSite.site_header = 'My site admin header'
admin.sites.AdminSite.site_title = 'My site admin title'
admin.sites.AdminSite.index_title = 'My site admin index'
其他回答
在urls.py中,你可以覆盖3个最重要的变量:
from django.contrib import admin
admin.site.site_header = 'My project' # default: "Django Administration"
admin.site.index_title = 'Features area' # default: "Site administration"
admin.site.site_title = 'HTML title from adminsitration' # default: "Django site admin"
参考:关于这些属性的Django文档。
你只需要覆盖admin/base_site.html模板(从django.contrib.admin.templates中复制模板并放入你自己的管理模板dir中)并替换branding块。
一个简单的方法是在项目文件夹中的urls.py文件中包含以下代码。
in urls.py add
admin.site.site_header = "Site Header here"
admin.site.site_title = "Side title"
admin.site.index_title = "Index title"
例如:
from django.contrib import admin
from django.urls import path
from django.conf.urls import include
from django.conf.urls.static import static
from django.conf import settings
admin.site.site_header = "Hadramawt Kitchen"
admin.site.site_title = "Hadramawt Kitchen"
admin.site.index_title = "Hadramawt Admin"
urlpatterns = [
path('admin/', admin.site.urls),
path('', include('food_products.urls' )),
path('categories', include('categories.urls' )),
path('news', include('news.urls')),
path('weeklyOffer', include('weekly_offer.urls'))
]+ static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
从Django 2.0开始,你只需要在url.py中添加一行代码并更改名称。
# url.py
from django.contrib import admin
admin.site.site_header = "My Admin Central" # Add this
对于较旧版本的Django。(<1.11或更早的版本),您需要编辑admin/base_site.html
改变这一行
{% block title %}{{ title }} | {{ site_title|default:_('Django site admin') }}{% endblock %}
to
{% block title %}{{ title }} | {{ site_title|default:_('Your Site name Admin Central') }}{% endblock %}
你可以检查你的django版本
django-admin --version
admin.py:
from django.contrib.admin import AdminSite
AdminSite.site_title = ugettext_lazy('My Admin')
AdminSite.site_header = ugettext_lazy('My Administration')
AdminSite.index_title = ugettext_lazy('DATA BASE ADMINISTRATION')