Usage

For Applications supporting django-templates

Provide your own templates, provide a django_templates.py file in your app directory. This file should contain a variable called DJANGO_TEMPLATES, which is a dictionary mapping template ids to template names and/or a get_django_templates() function, which returns a dictionary mapping template ids to template names. The function is called with the CSS framework as an argument.

DJANGO_TEMPLATES = {
    'my-app/my-template': 'my-app/some-subderictory/my-template.html',
}

def get_django_templates(css_framework: str) -> dict:
    if css_framework in ['bootstrap', 'bootstrap5']:
        return {
            'my-app/my-template': 'my-app/bootstrap/my-template.html',
        }
    elif css_framework == 'tailwindcss':
        return {
            'my-app/my-template': 'my-app/tailwindcss/my-template.html',
        }
    else:
        return {
            'my-app/my-template': 'my-app/html/my-template.html',
        }

BASE_TEMPLATE

To make use of the BASE_TEMPLATE setting in your views, set the BASE_TEPMPLATE pointing to the template you want to use as the base template. It is then set as as a context variable that can be accessed in your templates using the BASE_TEMPLATE variable by the context processor.

BASE_TEMPLATE = 'base.html'

In your views, you can then extend BASE_TEMPLATE in your templates using the extends tag.

{% extends BASE_TEMPLATE %}

If you don’t set BASE_TEMPLATE, the default value of base.html will be used.

DJANGO_TEMPLATES

The DJANGO_TEMPLATES in your settings.py allows you to override the application’s templates by providing your own templates. This is a dictionary that maps template ids to template names.

DJANGO_TEMPLATES = {
    'my-app/my-template': 'my-app/some-subderictory/my-template.html',
}

To access the tmplates in your html_templates load templates in your . Then you can access it tih the templates filter. This might be useful if you want to include a template from a different app.

{% load templates %}

{% include "my-app/my-template"|template %}