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.4.2.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 30940ce740615ce68d5d51d3c143fe7b577b7992120c2bf1b27f00dffa4d1b2f |
|
MD5 | 0b371442c64c7a841ac5f28205b14a2d |
|
BLAKE2b-256 | 931f2686859574384ce285ea3b5eea1e94b04bea396cfe8d2720363c69c5ee83 |
Close
Hashes for starlette_async_jinja-1.4.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 374f1d36b9eaf4f665a9e6c732be96bf2132684b26db4108d6af984659c92713 |
|
MD5 | d32297596a7d9a724bcded405789f7ca |
|
BLAKE2b-256 | c5ff5e8306be268fb2f17a697e30a29c9351e237a00a960c2e21b7c53310f21f |