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
bareasgi-jinja2-4.0.1.tar.gz
(7.2 kB
view details)
Built Distribution
File details
Details for the file bareasgi-jinja2-4.0.1.tar.gz
.
File metadata
- Download URL: bareasgi-jinja2-4.0.1.tar.gz
- Upload date:
- Size: 7.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.12 CPython/3.10.6 Darwin/21.6.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a1542973f01d0caeecbccc9dab96d967f4f0597112853173013e4ccbac82cd53 |
|
MD5 | cfc05d03e7a6a0132afae38960e70665 |
|
BLAKE2b-256 | bfb901428591a15ecff3d9a8fc03b0fdf437fa4d4418ab141ebd9e1abb1f926c |
File details
Details for the file bareasgi_jinja2-4.0.1-py3-none-any.whl
.
File metadata
- Download URL: bareasgi_jinja2-4.0.1-py3-none-any.whl
- Upload date:
- Size: 7.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.12 CPython/3.10.6 Darwin/21.6.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0c95849e1984c4b3260a04d5f6b077fb98a4fd197b64e22c153bbcac3441df6a |
|
MD5 | 855c7bed168a39b27f7d93ade79fd266 |
|
BLAKE2b-256 | 48bec42e58f8437c78b45475b520ff912a3b15c20e44278e85b8b7618f9b95d2 |