Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

django: how do I actually override admin site template

I know this is asked and answered several times but I basically went over all the post on stack overflow and still couldn't get this to work. Right now I am just trying simply change the admin site title. I have the following:

#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 %}

And I tried to put this in

my_site/templates/admin/base_site.html,

my_site/templates/admin/my_app/base_site.html, and

my_site/my_app/templates/admin/base_site.html,

but none of these work.

settings.py:
TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [os.path.join(BASE_DIR, 'templates')],
        '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',
            ],
            'loaders': [
                'django.template.loaders.filesystem.Loader',
                'django.template.loaders.app_directories.Loader',
            ],
        },
    },
]

I also tried just directly changing django\contrib\admin\templates\admin\base_site.html but still nothing happens.

I am really frustrated now and definitely could use some help, thanks

Updates: Actually I found out that the local template does have effect. enter image description here

Like here, the topmost white bar displays "#base_site.html!!@#" which is what I put in my_site/templates/admin/base_site.html as a comment by chance. So it kinda working, but I still don't understand why I can't change the site title.

like image 757
Hansong Li Avatar asked Aug 24 '16 20:08

Hansong Li


1 Answers

Add your Django app above ‘Django.contrib.admin’ in settings.INSTALLED_APPS. The ordering matters.

use my_site/my_app/templates/admin/base_site.html

put your app where you define this template before 'django.contrib.admin', in INSTALLED_APPS

source link

like image 122
Mohit Rustagi Avatar answered Oct 01 '22 08:10

Mohit Rustagi