如何更改Django admin头中的“Django administration”文本?

“自定义管理”文档中似乎没有涉及到这一点。


当前回答

从Django 1.7开始,你不需要重写模板。现在,您可以在自定义AdminSite上实现site_header、site_title和index_title属性,以便轻松更改管理站点的页面标题和标题文本。创建一个AdminSite子类,并将你的实例绑定到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)),
)

更新:正如oxfn所指出的,你可以直接在urls.py或admin.py中设置site_header,而不需要子类化AdminSite:

admin.site.site_header = 'My administration'

其他回答

基于这个问题的答案,在Django 1.8.3中给出了一个简单完整的解决方案。

在settings.py中添加:

ADMIN_SITE_HEADER = "My shiny new administration"

在urls.py中添加:

from django.conf import settings
admin.site.site_header = settings.ADMIN_SITE_HEADER

在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.py文件。

admin.site.site_header = 'your_header'
admin.site.site_title = 'site_title'
admin.site.index_title = 'index_title'

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')

有一个简单的方法来设置管理站点头-分配给当前的管理实例在urls.py像这样

admin.site.site_header = 'My admin'

或者你也可以用另一种方法来实现一些创建头部的魔法

admin.site.site_header = get_admin_header()

因此,在简单的情况下,不需要继承AdminSite的子类