Relative path in TEMPLATES setting

The TEMPLATE setting is a list of the template engines used when finding template files and rendering them.

The DIRS key within the TEMPLATE list denotes the directories where the engine should look for template source files.

DIRS must be absolute paths. Relative paths will not work.

So in practice, do this


import os

ROOT = os.path.abspath(os.path.dirname(__file__))
    
TEMPLATES = [
    {
        # …
        'DIRS': [os.path.join(ROOT, 'templates')],
    }
}

Instead of this


TEMPLATES = [
    {
        # …
        'DIRS': ['templates'],
    }
}

Are you affected by this? Audit your codebase in seconds to find out.

Configuring this check

Django Doctor will run this check by default. No configuration is needed but the check can be turned on/off using check code template-dir-relative in your pyproject.toml file.

Read more about configuring Django Doctor.