Async version of Jinja2.
This library contains a wrappers for the standard Jinja2 library.
In addition to Jinja's built-in enable_async
, the following has been added:
- async loaders, like
FileSystemLoader
via aiofiles - async bytecode cache (aioredis and aiocache supported)
- async version of the Environment.compile_templates method
Notice: Keep in mind that the enable_async
option is forced to True
in order to compile templates correctly. In particular, this means that
you should use Template.render_async
method instead of Template.render
.
pip install aioja
from aioja.environment import Environment
from aioja.loaders import FileSystemLoader
from aioja.bccache.aiocache import AioCacheBytecodeCache
env = Environment(
loader=FileSystemLoader('templates'),
# ...
# bytecode_cache=AioCacheBytecodeCache()
# ...
)
template = await env.get_template('index.html')
content = await template.render_async({
'page_id': 123
})