template#
- class litestar.template.TemplateConfig#
Bases:
Generic[EngineType]Configuration for Templating.
To enable templating, pass an instance of this class to the
Litestarconstructor using the ‘template_config’ key.- __init__(engine: type[EngineType] | EngineType | None = None, directory: PathType | list[PathType] | None = None, engine_callback: Callable[[EngineType], None] | None = None, instance: EngineType | None = None) None#
- directory: PathType | list[PathType] | None = None#
A directory or list of directories from which to serve templates.
- engine: type[EngineType] | EngineType | None = None#
A template engine adhering to the
TemplateEngineProtocol.
- engine_callback: Callable[[EngineType], None] | None = None#
A callback function that allows modifying the instantiated templating protocol.
- property engine_instance: EngineType#
Return the template engine instance.
- to_engine() EngineType#
Instantiate the template engine.
- class litestar.template.TemplateEngineProtocol#
Bases:
Protocol[TemplateType_co,ContextType_co]Protocol for template engines.
- __init__(directory: Path | list[Path] | None, engine_instance: Any | None) None#
Initialize the template engine with a directory.
- get_template(template_name: str) TemplateType_co#
Retrieve a template by matching its name (dotted path) with files in the directory or directories provided.
- Parameters:
template_name¶ – A dotted path
- Returns:
Template instance
- Raises:
TemplateNotFoundException – if no template is found.
- register_template_callable(key: str, template_callable: Callable[[Concatenate[ContextType_co, P]], R]) None#
Register a callable on the template engine.