quart.templating module

class quart.templating.Environment(app, **options)

Bases: Environment

Quart specific Jinja Environment.

This changes the default Jinja loader to use the DispatchingJinjaLoader, and enables async Jinja by default.

Parameters:
  • app (Quart)

  • options (Any)

async quart.templating.render_template(template_name_or_list, **context)

Render the template with the context given.

Parameters:
  • template_name_or_list (str | list[str]) – Template name to render of a list of possible template names.

  • context (Any) – The variables to pass to the template.

Return type:

str

async quart.templating.render_template_string(source, **context)

Render the template source with the context given.

Parameters:
  • source (str) – The template source code.

  • context (Any) – The variables to pass to the template.

Return type:

str

async quart.templating.stream_template(template_name_or_list, **context)

Render a template by name with the given context as a stream.

This returns an iterator of strings, which can be used as a streaming response from a view.

Parameters:
  • template_name_or_list (str | Template | list[str | Template]) – The name of the template to render. If a list is given, the first name to exist will be rendered.

  • context (Any) – The variables to make available in the template.

Return type:

AsyncIterator[str]

async quart.templating.stream_template_string(source, **context)

Render a template from the given source with the context as a stream.

This returns an iterator of strings, which can be used as a streaming response from a view.

Parameters:
  • source (str) – The source code of the template to render.

  • context (Any) – The variables to make available in the template.

Return type:

AsyncIterator[str]