No project description provided
Project description
starlette-async-jinja
Jinja2 is_async template support for Starlette +
About
- Provides AsyncJinja2Templates class which enables use of the is_async Jinja environment flag with Startlette and Starlette based applications like FastAPI
- Integrated Jinja Partials and Jinja Fragments
- Supports asynchronous template loaders (examples here) (not yet tested but should work)
Issues
-
Only asynchronous template loaders (not yet tested but should work) are currently supported
-
The Jinja bytecodecache requires an asynchronous Redis backend
Usage
Import AsyncJinja2 Templates:
from starlette_async_jinja import AsyncJinja2Templates
Replace Jinja2Templates with AsyncJinja2Templates:
templates = Jinja2Templates(directory='templates')
Render the async template in the response:
async def homepage(request: Request):
return await templates.AsyncTemplateResponse('index.html', {'request': request})
Even simpler:
async def homepage(request: Request):
return await templates.render_template('index.html', {'request': request})
To render Jinja Fragments or 'blocks':
async def only_block(request: Request):
return await templates.render_block(
"page.html.jinja2",
{"request": request, "magic_number": 42},
block_name="content"
)
To render Jinja Partials:
in a template
{% for v in row %}
<div class="col-md-3 video">
{{ render_partial('shared/partials/video_square.html', video=v) }}
</div>
{% endfor %}
or programmatically
async def render_partial(template: str, **kwargs):
return await templates.render_partial(template, **kwargs)
Acknowledgements
License
BSD-3-Clause
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 starlette_async_jinja-1.3.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2b4c4c87bdda42a0b2001867f7f8301dbd641155a174bd18d0cb7d8f1ff97bbd |
|
MD5 | 905bbd2f05ea0effa439aa41f8091883 |
|
BLAKE2b-256 | 0dfa740afa34c33a9ebee5cd0a39a9e36496eaba51285d0570a084081cfb05ad |
Close
Hashes for starlette_async_jinja-1.3.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0fba1a4a17097d5cd167148556d31bbf1a7162d8371a1f70d13915b6e10507cb |
|
MD5 | 87a70c54a68a05c6026be76460f4bd2c |
|
BLAKE2b-256 | 7123d9b5887817e96aec92ded33c5d0eadf83df896c30054a0270a782f947878 |