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.2.6.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0ab8b5d34fc2079e40d69f531f0e45b5032c468ce24fec8ce1ca45985378c78e |
|
MD5 | 25247523d8d20b6192564433df22de60 |
|
BLAKE2b-256 | d17245d1eddfa899deef20d477eff6707ce22e0af8f54026973e3217d3565b87 |
Close
Hashes for starlette_async_jinja-1.2.6-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d4d2c496d307fcc25158777d8ea701dde302adccf0cf01037fbc1b49b9468037 |
|
MD5 | ecf09e7374b0c7fe146ecc1b743ea984 |
|
BLAKE2b-256 | 150d180364d959c856e6c61e6cc7a273207e91848de8e1db2725d5481a0d164c |