Django template configuration

By default, Django templates are enabled on all Django projects due to the TEMPLATES variable in settings.py. Listing 3-1 illustrates the default TEMPLATES value in Django projects.

Listing 3-1. Default Django template configuration in settings.py

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

The BACKEND variable indicates the project uses Django templates. The DIRS and APP_DIRS variables tell Django where to locate Django templates and are explained in the next section. The context_processors field inside OPTIONS tells Django which context processors to enable for a Django project. In short, a context processor offers the ability to share data across all Django templates, without the need to define it in a piecemeal fashion in Django views.

Later sections in this chapter describe what data is provided by default Django context processors and how to write your own context processors to share custom data on all Django templates.