Jinja2 support for bareasgi
Project description
bareASGI-jinja2
Jinja2 support for bareASGI (read the documentation)
Usage
Try the following.
from typing import Mapping, Any
import jinja2
import os.path
import uvicorn
from bareasgi import Application
from bareasgi_jinja2 import Jinja2TemplateProvider, add_jinja2
here = os.path.abspath(os.path.dirname(__file__))
async def http_request_handler(request: HttpRequest) -> HttpResponse:
"""Handle the request"""
template = 'example1.html'
variables = {'name': 'rob'}
return await Jinja2TemplateProvider.apply(request, template, variables)
app = Application()
env = jinja2.Environment(
loader=jinja2.FileSystemLoader(os.path.join(here, 'templates')),
autoescape=jinja2.select_autoescape(['html', 'xml']),
enable_async=True
)
add_jinja2(app, env)
app.http_router.add({'GET'}, '/example1', http_request_handler)
uvicorn.run(app, port=9010)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Close
Hashes for bareasgi_jinja2-4.0.0a0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 68a8ec61ed9cb40dfade78d68900bf0b50c5ddfdc5300127ddc80dff9da111ad |
|
MD5 | e98279466a4b4aeeae92e46f10dda64a |
|
BLAKE2b-256 | 5bcabf74e78f00a532e008e2161cf6d5a0fbf8bfc09c5239491e1015fae3bb9f |