Django Admin - change header 'Django administration' text

后端 未结 18 2300
眼角桃花
眼角桃花 2020-11-28 01:14

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.

18条回答
  •  自闭症患者
    2020-11-28 01:39

    There are two methods to do this:

    1] By overriding base_site.html in django/contrib/admin/templates/admin/base_site.html: Following is the content of base_site.html:

    {% extends "admin/base.html" %}
    
    {% block title %}{{ title }} | {{ site_title|default:_('Django site admin') }}{% endblock %}
    
    {% block branding %}
    

    {{ site_header|default:_('Django administration') }}

    {% endblock %} {% block nav-global %}{% endblock %}

    Edit the site_title & site_header in the above code snippet. This method works but it is not recommendable since its a static change.

    2] By adding following lines in urls.py of project's directory:

    admin.site.site_header = "AppHeader"
    admin.site.site_title = "AppTitle"
    admin.site.index_title = "IndexTitle"
    admin.site.site_url = "Url for view site button"
    

    This method is recommended one since we can change the site-header, site-title & index-title without editing base_site.html.

提交回复
热议问题