Templates
Jinja2Renderer
Jinja2Renderer(directory)
Template renderer to make Jinja2 easier in Air.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
directory
|
str
|
Template directory |
required |
Example
Instantiate the render callable
jinja = TemplateRenderer('templates')
Use for returning Jinja2 from views
@app.get('/') async def home(request: Request): return jinja( ... request, ... 'home.html', ... context={'id': 5} ... )
Can also pass in kwargs, which will be added to the context:
>>> return jinja(
... request,
... 'home.html',
... name='Parmesan'
... )
Initialize with template directory path
Source code in src/air/templates.py
35 36 37 |
|
__call__
__call__(request, name, context=None, **kwargs)
Render template with request and context
Source code in src/air/templates.py
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
|