Customize the admin look and feel HTML not overwriting: Customizing your project’s templates

Hello, apologies for the simple question but i have spent a significant amout of time on this:

Tutorial 7 where you customise the admin base_site.html to redirect to your own templates. Mines refuses to override. This is my dir structure:

(venv) ➜  mysite tree
.
├── db.sqlite3
├── manage.py
├── mysite
│   ├── __init__.py
│   ├── __pycache__
│   │   ├── __init__.cpython-312.pyc
│   │   ├── settings.cpython-312.pyc
│   │   ├── urls.cpython-312.pyc
│   │   └── wsgi.cpython-312.pyc
│   ├── asgi.py
│   ├── settings.py
│   ├── urls.py
│   └── wsgi.py
├── polls
│   ├── __init__.py
│   ├── __pycache__
│   │   ├── __init__.cpython-312.pyc
│   │   ├── admin.cpython-312.pyc
│   │   ├── apps.cpython-312.pyc
│   │   ├── models.cpython-312.pyc
│   │   ├── tests.cpython-312.pyc
│   │   ├── urls.cpython-312.pyc
│   │   └── views.cpython-312.pyc
│   ├── admin.py
│   ├── apps.py
│   ├── migrations
│   │   ├── 0001_initial.py
│   │   ├── __init__.py
│   │   └── __pycache__
│   │       ├── 0001_initial.cpython-312.pyc
│   │       └── __init__.cpython-312.pyc
│   ├── models.py
│   ├── static
│   │   └── polls
│   │       ├── images
│   │       │   └── giraffe_background.jpeg
│   │       └── style.css
│   ├── templates
│   │   └── polls
│   │       ├── detail.html
│   │       ├── index.html
│   │       └── results.html
│   ├── tests.py
│   ├── urls.py
│   └── views.py
└── templates
    └── admin
        └── base_site.html

This is my settings.py TEMPLATES:

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [BASE_DIR / "templates"], 
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

and the base_site.html at documentation/mysite/templates/admin

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

{% block title %}{% if subtitle %}{{ subtitle }} | {% endif %}{{ title }} | {{ site_title|default:_('Django site admin') }}{% endblock %}

{% block branding %}
<div id="site-name"><a href="{% url 'admin:index' %}">{{ site_header|default:_('Polling administration') }}</a></div>
{% if user.is_anonymous %}
  {% include "admin/color_theme_toggle.html" %}
{% endif %}
{% endblock %}

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

Restarted server several times and there is no unsaved changes. Thanks!

What are your TEMPLATES in settings.py?

  1. Make sure the DIRS option in the TEMPLATES setting points to the correct directory where your base_site.html file is located. In your case, it should be BASE_DIR / "templates/admin".

  2. Double-check that the APP_DIRS option is set to True. This allows Django to look for templates within the templates directory of each installed app.

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [BASE_DIR / "templates/admin"], 
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

In the base_site.html file, you need to replace the entire {{ site_header|default:_('Django administration') }} section (including the curly braces) with “Polls administration”. In your example, you only replaced the default filter value, which only displays if the site_header attribute is blank.

By default, the site_header attribute is “Django administration” so the default value you’re providing is not being used.

The site name div should be:

<div id="site-name"><a href="{% url 'admin:index' %}">Polls administration</a></div>

I made the same mistake!