starlette.Templates
Starlette’s Jinja2Templates for chameleon-rs templates.
Usage
starlette.Templates()directory: the template folder (or a list of folders, searched in order). Left out, the templates come from the process-wide configuration (chameleon_rs.configure / configure in this module), looked up at each render. context_processors: functions taking the request and returning a dict added to each template’s context. auto_reload / restricted_namespace (with directory): the loader’s options (None: Chameleon’s defaults, CHAMELEON_RELOAD for reloading).
Attributes
| Name | Description |
|---|---|
| loader | The TemplateLoader templates come from (the configured one when no directory was |
loader
The TemplateLoader templates come from (the configured one when no directory was
loader: TemplateLoader
given).
Methods
| Name | Description |
|---|---|
| TemplateResponse() | Renders a template to an HTML response (Starlette’s TemplateResponse). Renders |
| TemplateResponse_async() | TemplateResponse rendering with render_async: awaitable values in the context |
| get_template() |
The page template name (relative to the template folder).
|
TemplateResponse()
Renders a template to an HTML response (Starlette’s TemplateResponse). Renders
Usage
TemplateResponse(
request,
name,
context=None,
status_code=200,
headers=None,
media_type=None,
background=None
)synchronously: in an async def endpoint, TemplateResponse_async does not block the event loop while the page renders.
TemplateResponse_async()
TemplateResponse rendering with render_async: awaitable values in the context
Usage
TemplateResponse_async(
request,
name,
context=None,
status_code=200,
headers=None,
media_type=None,
background=None,
*,
concurrent=None,
offload=False
)are awaited where the template uses them, without blocking the event loop. concurrent=True fans native partials with awaitable arguments out (None keeps the template’s setting); offload=True (experimental) renders in a worker thread.
get_template()
The page template name (relative to the template folder).
Usage
get_template(name)Raises chameleon_rs.web.TemplateNotFound (a ValueError) if no folder has it, or if the name could reach outside the folder (absolute, .., a backslash, a drive letter or a package spec), as Jinja’s FileSystemLoader refuses such names. (Only here: PageTemplateLoader and the decorator API raise Chameleon’s ValueError.)