mako

class litestar.contrib.mako.MakoTemplate[原始碼]

基底類別:TemplateProtocol

Mako template, implementing TemplateProtocol

__init__(template: Template, template_callables: list[tuple[str, Callable[[Concatenate[ContextType, P]], R]]]) None[原始碼]

Initialize a template.

參數:
  • 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.

參數:
  • args -- Positional arguments passed to the engines render function

  • kwargs -- Keyword arguments passed to the engines render function

回傳:

Rendered template as a string

class litestar.contrib.mako.MakoTemplateEngine[原始碼]

基底類別:TemplateEngineProtocol[MakoTemplate, Mapping[str, Any]]

Mako-based TemplateEngine.

__init__(directory: Path | list[Path] | None = None, engine_instance: Any | None = None) None[原始碼]

初始化模板引擎。

參數:
  • directory -- Direct path or list of directory paths from which to serve templates.

  • engine_instance -- A mako TemplateLookup instance.

get_template(template_name: str) MakoTemplate[原始碼]

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

參數:

template_name -- A dotted path

回傳:

MakoTemplate 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.

參數:
  • key -- The callable key, i.e. the value to use inside the template to call the callable.

  • template_callable -- A callable to register.

回傳:

None

render_string(template_string: str, context: Mapping[str, Any]) str[原始碼]

Render a template from a string with the given context.

參數:
  • template_string -- The template string to render.

  • context -- A dictionary of variables to pass to the template.

回傳:

The rendered template as a string.

classmethod from_template_lookup(template_lookup: TemplateLookup) MakoTemplateEngine[原始碼]

Create a template engine from an existing mako TemplateLookup instance.

參數:

template_lookup -- A mako TemplateLookup instance.

回傳:

MakoTemplateEngine instance