mako#

class starlite.contrib.mako.MakoTemplate#

Bases: TemplateProtocol

Mako template, implementing TemplateProtocol

__init__(template: _MakoTemplate, template_callables: List[Tuple[str, Callable[[Dict[str, Any]], Any]]])#

Initialize a template.

Parameters:
  • template – Base MakoTemplate used by the underlying mako-engine

  • template_callables – List of callables passed to the template

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

Render a template.

Parameters:
  • args – Positional arguments passed to the engines render function

  • kwargs – Keyword arguments passed to the engines render function

Returns:

Rendered template as a string

class starlite.contrib.mako.MakoTemplateEngine#

Bases: TemplateEngineProtocol[MakoTemplate]

Mako based TemplateEngine.

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

Initialize template engine.

Parameters:

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

get_template(template_name: str) MakoTemplate#

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

Returns:

MakoTemplate 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