jinja¶
- class litestar.contrib.jinja.JinjaTemplateEngine[源代码]¶
基类:
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.
- 参数:
template_name¶ -- A dotted path
- 返回:
JinjaTemplate instance
- 抛出:
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.
- 参数:
jinja_environment¶ (jinja2.environment.Environment) -- A jinja Environment instance.
- 返回:
JinjaTemplateEngine instance