[Django]-Which template shows the words "Site administration" under the colored horizontal banner in Django's admin page?

3👍

Give the docs a read; admin docs and customising look and feel

Its a simple case of setting up a template for the admin which overwrites the default;

The template to customize 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 custom template directory.) Edit the file, and you’ll see it uses a template variable called app_list. That variable contains every installed Django app. Instead of using that, you can hard-code links to object-specific admin pages in whatever way you think is best. Again, don’t worry if you can’t understand the template language — we’ll cover that in more detail in Tutorial 3.

I went through all the tutorials in the Django docs I linked to a couple of weeks back but can’t find an example of a custom Admin template, but this site looks like it’ll certainly help you understand it;

http://blog.montylounge.com/2009/07/5/customizing-django-admin-branding/

3👍

The title _("Site administration") is defined the sites.py file under contrib/admin/. Either you change that string there and have to remember to change it every time you upgrade Django (not recommended) or you override the base_site.html template and add the title manually there.

👤Mikael

0👍

Thought I’d add a more up-to-date reference for this old question, seeing as it’s still viewed and active, and I find the docs overwhelmingly thorough.

Subclass AdminSite to rename template variables

myapp/admin.py

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')
admin_site.register(MyModel)

myproject/urls.py

from django.conf.urls import url

from myapp.admin import admin_site

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

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

The properties you can customise on your admin_site are:

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

In addition, you can extend the default admin templates:

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

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

Ref: 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 the templates in individual ModelAdmin and TabularInline, etc classes.


There’s a fair bit of inheritance going on throughout django-admin, so installing Django Debug Toolbar is very helpful for figuring out what to extend (and where your override should be placed in the templates directory).

👤ptim

Leave a comment