Search code examples
pythondjangodjango-templatesdjango-admindjango-settings

Why can't I override the Django Admin template?


I can't change my Django admin template. I have followed the instructions from the Django documentation, and I have already checked StackOverflow questions.

I have already made /templates/admin/my_app/, and changed base_site.html in /templates/admin/my_app/base_site.html

settings.py:

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [os.path.join(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',
            ],
        },
    },
]

base_site.html:

#base_site.html
{% extends "admin/base_site.html" %}

{% block title %}{{ title }} | {{ site_title|default:_('NEW TITLE') }}{% 
endblock %}

{% block branding %}
<h1 id="site-name"><a href="{% url 'admin:index' %}">{{ 
site_header|default:_('NEW TITLE') }}</a></h1>
{% endblock %}

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

File Structure:

my_project
└── my_project
    └── templates
        └── admin
           └── my_app
                └── base_site.html

Why can't I override the Django Admin template?


Solution

  • base_site.html should be placed in /templates/admin folder itself as shown below:

    /templates/admin/base_site.html instead of /templates/admin/my_app/base_site.html