2

I don't get django 1.11 to accept a new base_site.html:

Following docs and some posts i copied the file to: BASE_DIR/templates/base_site.html and BASE_DIR/templates/admin/base_site.html

in 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 tried that with the file in templates and in templates/admin:

>>> print ( os.path.isfile((os.path.join(settings.BASE_DIR, 'templates', 'admin','base_site.html'))) )
True
>>> print ( os.path.isfile((os.path.join(settings.BASE_DIR, 'templates', 'base_site.html'))) )
True
dev langer
  • 202
  • 1
  • 11

3 Answers3

2

If you want to override admin files they must exist in admin folder inside templates folder like below
your_project

your_project
     |-- your_project/
     |-- myapp/
     |-- templates/
          |-- admin/
             |-- base_site.html

here file name base_site.html must be same as the file name in original admin folder.

base_site.html

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

# you can write changes here
nivas
  • 3,138
  • 3
  • 16
  • 15
  • That's what i've seen in the docs, and what it actually looks like now. But django seems not to use it. – dev langer Aug 24 '17 at 06:17
  • problem is: I would have suspected it to work exactly the way you describe it. But the file is in that location (see prints above) and starts with {% extends (it is a copy with modifications in the title and branding block). But django seems not to use it. – dev langer Aug 24 '17 at 06:26
  • @devlanger look inside your app folders you might have `base_site.html` exist. you must not have the same file within other folders it will override you custom admin `base_site.html` file – nivas Aug 24 '17 at 06:32
1

Just had this problem and literally fixed it by installing django-apptemplates and adding it as a loader into settings.py:

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [PROJECT_DIR],
        'APP_DIRS': False,
        'OPTIONS': {
            'loaders': [
                # ADD LOADER HERE
                'apptemplates.Loader',
                'django.template.loaders.filesystem.Loader',
                'django.template.loaders.app_directories.Loader',
            ],
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

**APP_DIRS will have to be set to False in order for this to work

Devin B.
  • 433
  • 4
  • 18
0

To override the base_site.html of Django admin, add the custom base_site.html such that it's path is BASE_DIR/templates/admin/base_site.html. This works in Django 1.11 as well.

Nair
  • 1
  • 2
  • Has been my first guess also, but i tried that. I am not sure what the correct settings are, for this, to work. – dev langer Aug 24 '17 at 06:09
  • This [post](https://stackoverflow.com/a/4938665/7372472) explains it in detail. Please check this [method](https://stackoverflow.com/a/36251770/7372472) also. – Nair Aug 24 '17 at 09:16