It's a peach

Jinja2 Templating

The package that provides jinja2 support is bareASGI-jinja2.


The package can be installed as follows.

pip install bareasgi-jinja2


A helper method can be used to add the support. Assuming the templates are in a folder named templates:

from bareasgi import Application,
import bareasgi_jinja2
import jinja2
import pkg_resources

app = Application(info=dict(config=config))

templates = pkg_resources.resource_filename(__name__, "templates")
env = jinja2.Environment(
    autoescape=jinja2.select_autoescape(['html', 'xml']),
bareasgi_jinja2.add_jinja2(app, env)

A decorator is applied to request handlers which use a jinja2 template.

import bareasgi_jinja2

async def handle_index_request(scope, info, matches, content):
    return {
        'title': 'bareASGI'

The decorator specifies the template to be used. The request handler returns a dict the values of which are available in the template.