jinja#

class starlite.contrib.jinja.JinjaTemplateEngine#

Bases: TemplateEngineProtocol[JinjaTemplate]

The engine instance.

__init__(directory: Union[DirectoryPath, List[DirectoryPath]]) None#

Jinja2 based TemplateEngine.

Parameters:

directory – Direct path or list of directory paths from which to serve templates.

get_template(template_name: str) JinjaTemplate#

Retrieve a template by matching its name (dotted path) with files in the directory or directories provided. :param template_name: A dotted path

Returns:

JinjaTemplate instance

Raises:

TemplateNotFoundException <starlite.exceptions.TemplateNotFoundException> – if no template is found.

register_template_callable(key: str, template_callable: Callable[[Dict[str, Any]], Any]) None#

Register a callable on the template engine.

Parameters:
  • key – The callable key, i.e. the value to use inside the template to call the callable.

  • template_callable – A callable to register.

Returns:

None