0

I have the following directory structure in my django 10 project:

/my-project/ # project dir
    +app1
    +templates
        +admin
            base.html
        404.html
        500.html

My templates attribute looks like this in settings:

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [
            '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',
                'common.context_processors.site_info',
            ],
        },
    },
]

My custom base.html displays on my local machine. When I upload this to my production server it no longer overrides and uses the base.html file in project folder.

I have changed around the order of apps suggested here and tried printing the dirs element of the templates attribute which prints "templates/" like here.

Does anyone know how I can get this to work on my production environment?

Community
  • 1
  • 1
Atma
  • 29,141
  • 56
  • 198
  • 299

1 Answers1

1

You must use absolute path in your settings to avoid issues. For example:

import os

PROJECT_ROOT = os.path.join(os.path.dirname(__file__), '..', '..')
# depending where your settings.py live

...
    'DIRS': [
        os.path.join(PROJECT_ROOT, 'templates'),
    ],
François Constant
  • 5,531
  • 1
  • 33
  • 39