template.backends.django.DjangoTemplates

class DjangoTemplates [source]

Set BACKEND to 'django.template.backends.django.DjangoTemplates' to configure a Django template engine.

When APP_DIRS is True, DjangoTemplates engines look for templates in the templates subdirectory of installed applications. This generic name was kept for backwards-compatibility.

DjangoTemplates engines accept the following OPTIONS:

  • 'autoescape': a boolean that controls whether HTML autoescaping is enabled.

    It defaults to True.

    Warning

    Only set it to False if you’re rendering non-HTML templates!

    New in Django 1.10:

    The autoescape option was added.

  • 'context_processors': a list of dotted Python paths to callables that are used to populate the context when a template is rendered with a request. These callables take a request object as their argument and return a dict of items to be merged into the context.

    It defaults to an empty list.

    See RequestContext for more information.

  • 'debug': a boolean that turns on/off template debug mode. If it is True, the fancy error page will display a detailed report for any exception raised during template rendering. This report contains the relevant snippet of the template with the appropriate line highlighted.

    It defaults to the value of the DEBUG setting.

  • 'loaders': a list of dotted Python paths to template loader classes. Each Loader class knows how to import templates from a particular source. Optionally, a tuple can be used instead of a string. The first item in the tuple should be the Loader class name, and subsequent items are passed to the Loader during initialization.

    The default depends on the values of DIRS and APP_DIRS.

    See Loader types for details.

  • 'string_if_invalid': the output, as a string, that the template system should use for invalid (e.g. misspelled) variables.

    It defaults to an empty string.

    See How invalid variables are handled for details.

  • 'file_charset': the charset used to read template files on disk.

    It defaults to the value of FILE_CHARSET.

  • 'libraries': A dictionary of labels and dotted Python paths of template tag modules to register with the template engine. This can be used to add new libraries or provide alternate labels for existing ones. For example:

    OPTIONS={
        'libraries': {
            'myapp_tags': 'path.to.myapp.tags',
            'admin.urls': 'django.contrib.admin.templatetags.admin_urls',
        },
    }
    

    Libraries can be loaded by passing the corresponding dictionary key to the {% load %} tag.

  • 'builtins': A list of dotted Python paths of template tag modules to add to built-ins. For example:

    OPTIONS={
        'builtins': ['myapp.builtins'],
    }
    

    Tags and filters from built-in libraries can be used without first calling the {% load %} tag.

New in Django 1.9:

The libraries and builtins arguments were added.

doc_Django
2016-10-09 18:39:43
Comments
Leave a Comment

Please login to continue.