starlite.template#

class starlite.template.TemplateEngineProtocol#

Bases: Protocol[T_co]

Protocol for template engines.

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

Initialize the template engine with a directory.

Parameters:

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

get_template(template_name: str) T_co#

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

Returns:

Template 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

class starlite.template.TemplateProtocol#

Bases: Protocol

Protocol Defining a Template.

Template is a class that has a render method which renders the template into a string.

render(*args: Any, **kwargs: Any) str#

Return the rendered template as a string.

Parameters:

**kwargs – A string keyed mapping of values passed to the TemplateEngine

Returns:

The rendered template string

__init__(*args, **kwargs)#
starlite.template.__getattr__(name: str) Any#

Provide lazy importing as per https://peps.python.org/pep-0562/