class Engine(dirs=None, app_dirs=False, context_processors=None, debug=False, loaders=None, string_if_invalid='', file_charset='utf-8', libraries=None, builtins=None, autoescape=True) [source]
When instantiating an Engine all arguments must be passed as keyword arguments:
-
dirsis a list of directories where the engine should look for template source files. It is used to configurefilesystem.Loader.It defaults to an empty list.
-
app_dirsonly affects the default value ofloaders. See below.It defaults to
False. -
autoescapecontrols whether HTML autoescaping is enabled.It defaults to
True.Warning
Only set it to
Falseif you’re rendering non-HTML templates!New in Django 1.10:The
autoescapeoption was added. -
context_processorsis 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 adictof items to be merged into the context.It defaults to an empty list.
See
RequestContextfor more information. -
debugis a boolean that turns on/off template debug mode. If it isTrue, the template engine will store additional debug information which can be used to display a detailed report for any exception raised during template rendering.It defaults to
False. -
loadersis a list of template loader classes, specified as strings. EachLoaderclass 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 theLoaderclass name, subsequent items are passed to theLoaderduring initialization.It defaults to a list containing:
'django.template.loaders.filesystem.Loader'-
'django.template.loaders.app_directories.Loader'if and only ifapp_dirsisTrue.
See Loader types for details.
-
string_if_invalidis the output, as a string, that the template system should use for invalid (e.g. misspelled) variables.It defaults to the empty string.
See How invalid variables are handled for details.
-
file_charsetis the charset used to read template files on disk.It defaults to
'utf-8'. -
'libraries': A dictionary of labels and dotted Python paths of template tag modules to register with the template engine. This is used to add new libraries or provide alternate labels for existing ones. For example:Engine( 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:Engine( builtins=['myapp.builtins'], )Tags and filters from built-in libraries can be used without first calling the
{% load %}tag.
The libraries and builtins arguments were added.
Please login to continue.