As of Django 1.7 you don't need to override templates. You can now implement site_header, site_title
, and index_title
attributes on a custom AdminSite in order to easily change the admin site’s page title and header text. Create an AdminSite subclass and hook your instance into your URLconf:
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'^myadmin/', include(admin_site.urls)),
)
Update: As pointed out by oxfn you can simply set the site_header
in your urls.py
or admin.py
directly without subclassing AdminSite
:
admin.site.site_header = 'My administration'
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…