Which template displays the words "Site Administration" under the colored horizontal banner on the Django admin page?

I want to change the words "Site Administration" to something else on the admin page. I tried a couple of commands grep

, but I couldn't find the correct pattern:

hobbes3@hobbes3 ~/Sites/mysite/site-packages/django/contrib/admin/templates $ grep -ri "site administration" .
hobbes3@hobbes3 ~/Sites/mysite/site-packages/django/contrib/admin/templates $ grep -ri "administration" .
./admin/base_site.html:<h1 id="site-name">{% trans 'Django administration' %}</h1>
hobbes3@hobbes3 ~/Sites/mysite/site-packages/django/contrib/admin/templates $ grep -ri "site" .
./admin/404.html:{% extends "admin/base_site.html" %}
./admin/500.html:{% extends "admin/base_site.html" %}
./admin/500.html:<p>{% trans "There been an error. It been reported to the site administrators via e-mail and should be fixed shortly. Thanks for your patience." %}</p>
./admin/auth/user/change_password.html:{% extends "admin/base_site.html" %}
./admin/base_site.html:{% block title %}{{ title }} | {% trans 'Django site admin' %}{% endblock %}
./admin/base_site.html:<h1 id="site-name">{% trans 'Django administration' %}</h1>
./admin/change_form.html:{% extends "admin/base_site.html" %}
./admin/change_form.html:    {% if has_absolute_url %}<li><a href="../../../r/{{ content_type_id }}/{{ object_id }}/" class="viewsitelink">{% trans "View on site" %}</a></li>{% endif%}
./admin/change_list.html:{% extends "admin/base_site.html" %}
./admin/delete_confirmation.html:{% extends "admin/base_site.html" %}
./admin/delete_selected_confirmation.html:{% extends "admin/base_site.html" %}
./admin/edit_inline/stacked.html:    {% if inline_admin_form.show_url %}<a href="../../../r/{{ inline_admin_form.original_content_type_id }}/{{ inline_admin_form.original.id }}/">{% trans "View on site" %}</a>{% endif %}
./admin/edit_inline/tabular.html:          {% if inline_admin_form.show_url %}<a href="../../../r/{{ inline_admin_form.original_content_type_id }}/{{ inline_admin_form.original.id }}/">{% trans "View on site" %}</a>{% endif %}
./admin/index.html:{% extends "admin/base_site.html" %}
./admin/invalid_setup.html:{% extends "admin/base_site.html" %}
./admin/login.html:{% extends "admin/base_site.html" %}
./admin/object_history.html:{% extends "admin/base_site.html" %}
./admin/object_history.html:    <p>{% trans "This object doesn't have a change history. It probably wasn't added via this admin site." %}</p>
./registration/logged_out.html:{% extends "admin/base_site.html" %}
./registration/logged_out.html:<p>{% trans "Thanks for spending some quality time with the Web site today." %}</p>
./registration/password_change_done.html:{% extends "admin/base_site.html" %}
./registration/password_change_form.html:{% extends "admin/base_site.html" %}
./registration/password_reset_complete.html:{% extends "admin/base_site.html" %}
./registration/password_reset_confirm.html:{% extends "admin/base_site.html" %}
./registration/password_reset_done.html:{% extends "admin/base_site.html" %}
./registration/password_reset_email.html:{% blocktrans %}You're receiving this e-mail because you requested a password reset for your user account at {{ site_name }}.{% endblocktrans %}
./registration/password_reset_email.html:{% trans "Thanks for using our site!" %}
./registration/password_reset_email.html:{% blocktrans %}The {{ site_name }} team{% endblocktrans %}
./registration/password_reset_form.html:{% extends "admin/base_site.html" %}


Am I looking at the wrong place or something?


After some digging, I think it has something to do with the {% block content_title %}{% endblock %}

inside base.html



Here's a screenshot of the words "Site Administration" I'm talking about on the admin home page.



source to share

3 answers

Give the documents read; admin docs and customizing appearance

This is a simple example of customizing a template for an administrator that overwrites the default,

The configuration template is admin / index.html. (Do the same as with admin / base_site.html in the previous section - copy it from the default directory to your own templates directory.) Edit the file and you will see that it uses a template variable called app_list. This variable contains all installed Django apps. Instead of using this, you can hard-code the links to the admin object pages in whatever way you think is best. Again, don't worry if you can't understand the templating language - we'll cover this in more detail in Tutorial 3.

I've looked through all the tutorials in the Django docs that I linked two weeks ago, but can't find an example of a custom admin template, but this site looks like it would help you understand it;




The header is _("Site administration")

defined by the sites.py

file in contrib/admin/

. Either you change this line, or you shouldn't change it every time you update Django (not recommended), or override the template base_site.html

and add the header there manually.



Thought I'd add a more up-to-date link to this old question after seeing that it is still being viewed and active and I find the docs overwhelmingly.

AdminSite subclass for renaming template variables


from django.contrib.admin import AdminSite

from .models import MyModel

class MyAdminSite(AdminSite):
    # this is the variable you asked about
    site_header = 'Monty Python administration'

admin_site = MyAdminSite(name='myadmin')



from django.conf.urls import url

from myapp.admin import admin_site

urlpatterns = [
    url(r'^myadmin/', admin_site.urls),


Link: https://docs.djangoproject.com/en/dev/ref/contrib/admin/#customizing-adminsite

properties you can configure on your admin_site:

site_header, site_title, site_url, index_title, index_template,
app_index_template, empty_value_display, login_template, login_form, 
logout_template, password_change_template, password_change_done_template


Extend admin templates

Alternatively, you can extend the default admin templates:

{% extends "admin/change_form.html" %}

{% block object-tools-items %}
    Let nuke this block and add custom content!
    The rest of the default change_form template remains the same.
{% endblock %}


Link: https://docs.djangoproject.com/en/dev/ref/contrib/admin/#overriding-admin-templates

Another example of this is adding a custom stylesheet:

{% extends "admin/base.html" %}
{% load static %}

{% block extrahead %}
    <link rel="stylesheet" href="{% static "my-app/admin-custom.css" %}">
{% endblock %}


This shows an override for all instances of change_form, but you can also override templates in separate ModelAdmin and TabularInline classes, etc.

There's a fair amount of inheritance out there on django-admin, so installing the Django Debug Toolbar is very helpful for figuring out what needs to be extended (and where your override should be placed in the templates directory).



All Articles