jinja#
- class litestar.contrib.jinja.JinjaTemplateEngine#
Bases:
TemplateEngineProtocol
[JinjaTemplate
,Mapping
[str
,Any
]]The engine instance.
- __init__(directory: Path | list[Path] | None = None, engine_instance: Environment | None = None) None #
Jinja-based TemplateEngine.
- get_template(template_name: str) JinjaTemplate #
Retrieve a template by matching its name (dotted path) with files in the directory or directories provided.
- Parameters:
template_name¶ – A dotted path
- Returns:
JinjaTemplate instance
- Raises:
TemplateNotFoundException – if no template is found.
- register_template_callable(key: str, template_callable: Callable[[Concatenate[Mapping[str, Any], P]], T]) None #
Register a callable on the template engine.
- render_string(template_string: str, context: Mapping[str, Any]) str #
Render a template from a string with the given context.
- classmethod from_environment(jinja_environment: Environment) JinjaTemplateEngine #
Create a JinjaTemplateEngine from an existing jinja Environment instance.
- Parameters:
jinja_environment¶ (jinja2.environment.Environment) – A jinja Environment instance.
- Returns:
JinjaTemplateEngine instance