Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/rob-blackbourn/bareasgi-jinja2
Jinja2 support for bareasgi
https://github.com/rob-blackbourn/bareasgi-jinja2
asgi asyncio bareasgi bareasgi-jinja2 jinja2 jinja2-support python web
Last synced: 4 days ago
JSON representation
Jinja2 support for bareasgi
- Host: GitHub
- URL: https://github.com/rob-blackbourn/bareasgi-jinja2
- Owner: rob-blackbourn
- License: apache-2.0
- Created: 2019-01-25T10:33:46.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2024-01-11T22:05:45.000Z (12 months ago)
- Last Synced: 2024-03-15T00:56:03.471Z (9 months ago)
- Topics: asgi, asyncio, bareasgi, bareasgi-jinja2, jinja2, jinja2-support, python, web
- Language: Jinja
- Homepage: https://rob-blackbourn.github.io/bareASGI-jinja2/
- Size: 1.44 MB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# bareASGI-jinja2
Jinja2 support for [bareASGI](http://github.com/rob-blackbourn/bareasgi)
(read the [documentation](https://rob-blackbourn.github.io/bareASGI-jinja2/))## Usage
Try the following.
```python
from typing import Mapping, Any
import jinja2
import os.path
import uvicorn
from bareasgi import Application
from bareasgi_jinja2 import Jinja2TemplateProvider, add_jinja2here = 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)
```