Skip to content

lesleslie/starlette-async-jinja

Repository files navigation

starlette-async-jinja

Code style: crackerjack

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)

Issues

  • Only asynchronous template loaders (not yet tested but should work) are currently supported

  • The Jinja bytecodecache requires an asynchronous Redis backend

Usage

Import AsyncJinja2Templates:

from starlette_async_jinja import AsyncJinja2Templates

Replace Jinja2Templates with AsyncJinja2Templates:

templates = AsyncJinja2Templates(directory='templates')

Render the async template in the response:

async def homepage(request: Request):
    return await templates.TemplateResponse(request, 'index.html')

or:

async def homepage(request: Request):
    return await templates.render_template(request, 'index.html')

Acknowledgements

License

BSD-3-Clause

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project

 

Packages

No packages published

Languages