Flask API

The Flask integration provides simplified functions for rendering blocks from Jinja2 templates within Flask applications.

API Reference

jinja2_fragments.flask.render_block(template_name, block_name, **context)[source]

Render a single block from a specified template.

This function renders a specific block within a template located in the template folder, using the provided context variables.

Parameters:
  • template_name (str) – The name of the template containing the block to render.

  • block_name (str) – The name of the block to render.

  • **context (Any) – Keyword arguments representing variables to be used as the context for the block.

Return type:

str

Returns:

The rendered string of the specified block.

jinja2_fragments.flask.render_blocks(template_name, block_names, **context)[source]

Render multiple blocks from a specified template.

This function renders multiple blocks within a template located in the template folder, using the provided context variables.

Parameters:
  • template_name (str) – The name of the template containing the blocks to render.

  • block_names (list[str]) – A list of block names to render.

  • **context (Any) – Keyword arguments representing variables to be used as the context for the blocks.

Return type:

str

Returns:

The rendered string of the specified blocks.