change header 'Django administration' text

How does one change the 'Django administration' text in the django admin header?

It doesn't seem to be covered in the "Customizing the admin" documentation.


Update : If you are using Django 1.7+, see the answer below.

Original answer from 2011: You need to create your own admin base_site.html template to do this. The easiest way is to create the file:

/<projectdir>/templates/admin/base_site.html

This should be a copy of https://github.com/django/django/blob/master/django/contrib/admin/templates/admin/base_site.html - except putting in your custom title:

{% block branding %}
<h1 id="site-name">{% trans 'my cool admin console' %}</h1>
{% endblock %}

For this to work, you need to have the correct settings for your project, namely in settings.py:

  • Make sure '/projectdir/templates/' is added into TEMPLATE_DIRS
  • Make sure 'django.template.loaders.filesystem.Loader' is added into TEMPLATE_LOADERS
  • See http://docs.djangoproject.com/en/dev/ref/settings/ for more information on settings.py


    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'
    

    There is an easy way to set admin site header - assign it to current admin instance in urls.py like this

    admin.site.site_header = 'My admin'
    

    Or one can implement some header-building magic in separate method

    admin.site.site_header = get_admin_header()
    

    Thus, in simple cases there's no need to subclass AdminSite

    链接地址: http://www.djcxy.com/p/62010.html

    上一篇: 如何重置Django管理员密码?

    下一篇: 更改标题'Django管理'文本