#django #python

If you want to override the site header and site title in your Django admin, most people start with overriding the admin templates. Even though that's a perfectly fine approach, I prefer to do it differently.

I first start with creating a subclass of admin.AdminSite:

mysite/admin.py

1from django.contrib import admin
2
3class YellowDuckAdminSite(admin.AdminSite):
4    site_header = "YellowDuck.be"
5    site_title = "YellowDuck.be"

Then, you need to use it as the default_site for your AdminConfig subclass:

mysite/apps.py

1from django.contrib.admin.apps import AdminConfig
2
3class YellowDuckAdminConfig(AdminConfig):
4    default_site = 'mysite.admin.YellowDuckAdminSite'

As the last step, you need to replace django.contrib.admin with your admin config class:

mysite/settings.py

1INSTALLED_APPS = [
2    ...
3    'mysite.apps.YellowDuckAdminConfig', # replaces django.contrib.admin
4    ...
5]

You can find more info in the documentation about this approach.