template¶
- class litestar.template.TemplateConfig[原始碼]¶
基底類別:
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.
- class litestar.template.TemplateEngineProtocol[原始碼]¶
基底類別:
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.
- 參數:
template_name¶ -- A dotted path
- 回傳:
Template instance
- 引發:
TemplateNotFoundException -- if no template is found.