Templates (Jinja)¶
- class microdot.jinja.Template(template, **kwargs)¶
A template object.
- Parameters:
template – The filename of the template to render, relative to the configured template directory.
kwargs – any additional options to be passed to the Jinja environment’s
get_template()method.
- jinja_env = None¶
The Jinja environment. The
initialize()method must be called before this attribute is accessed.
- classmethod initialize(template_dir='templates', enable_async=False, **kwargs)¶
Initialize the templating subsystem.
This method is automatically invoked when the first template is created. The application can call it explicitly if custom options need to be provided.
- Parameters:
template_dir – the directory where templates are stored. This argument is optional. The default is to load templates from a templates subdirectory.
enable_async – set to
Trueto enable the async rendering engine in Jinja, and therender_async()andgenerate_async()methods.kwargs – any additional options to be passed to Jinja’s
Environmentclass.
- name¶
The name of the template.
- generate(*args, **kwargs)¶
Return a generator that renders the template in chunks, with the given arguments.
- render(*args, **kwargs)¶
Render the template with the given arguments and return it as a string.
- generate_async(*args, **kwargs)¶
Return an asynchronous generator that renders the template in chunks, using the given arguments.
- async render_async(*args, **kwargs)¶
Render the template with the given arguments asynchronously and return it as a string.