Django templates

Django templates

Django templates — Contains the static parts of the desired HTML output as well as some special syntax describing how dynamic content will be inserted.

Django templates — Text document or a Python string marked-up using the Django template language.

The template system isn’t safe against untrusted template authors. For example, a site shouldn’t allow its users to provide their own templates, since template authors can do things like perform XSS attacks and access properties of template variables that may contain sensitive information.

Demonstration code

{% if user.is_authenticated %}Hello, {{ user.username }}.{% endif %}

Configuration

Templates engines are configured with the TEMPLATES setting.

Demonstration code

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [],
        'APP_DIRS': True,
        'OPTIONS': {
            # ... some options here ...
        },
    },
]

Django templates — Structure map

Clickable & Draggable!

Django templates — Related pages: