Skip to content

API

function bareasgi_jinja2.add_jinja2

Summary

Adds jinja2 support ro bareASGI.

Description

This helper function can be used as follows:

app = Application()

env = jinja2.Environment(
    loader=jinja2.FileSystemLoader('/path/to/templates')),
    autoescape=jinja2.select_autoescape(['html', 'xml']),
    enable_async=True
)

add_jinja2(app, env)
bareasgi_jinja2.add_jinja2(
app: Application,
env: jinja2.Environment,
info_key: Optional[str]
) -> Any

Parameters

app: Application

The bareASGI Application.

env: jinja2.Environment

The jinja2 Environment

info_key: Optional[str] (optional)

An optional key to overide the key in the supplied info dict where the jinja2 Environment is held. Defaults to None.

Returns

Any:

class Jinja2TemplateProvider

Summary

The bareASGI Jinja2 template provider

bareasgi_jinja2.Jinja2TemplateProvider(
env: jinja2.Environment
) -> None

Parameters

env: jinja2.Environment

The jinja2 environment

async class method Jinja2TemplateProvider.apply


async Jinja2TemplateProvider.apply(
template_name: str,
variables: Mapping[strAny],
*,
status: int,
encoding: str,
info_key: str
) -> HttpResponse

Parameters

template_name: str

variables: Mapping[strAny]

status: int (optional)

encoding: str (optional)

info_key: str (optional)

Returns

HttpResponse:

async method Jinja2TemplateProvider.render_string

Summary

render a string from a template and variables.

async Jinja2TemplateProvider.render_string(
template_name: str,
variables: Mapping[str, Any]
) -> str

Parameters

template_name: str

The name of the template

variables: Mapping[str, Any]

The variables to use

Returns

str: The renderable string