Skip to main content

No project description provided

Project description

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

starlette_async_jinja-1.7.11.tar.gz (4.8 kB view hashes)

Uploaded Source

Built Distribution

starlette_async_jinja-1.7.11-py3-none-any.whl (5.3 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page