Templates¶
app.templates() returns a Templates. The guide shows the
syntax and the filters; this page lists the classes.
Templates ¶
Templates(directory: Union[str, Path], *, reload: bool = False)
Render HTML templates from a folder.
Templates are compiled the first time they are used, then cached.
templates = Templates("templates")
html = templates.render("index.html", {"user": "Ada"})
Set reload=True to pick up edited files. The guide:
https://3d3n-pyc.github.io/korvex/templates/
Serve templates from directory; reload recompiles a template when its files change.
render ¶
render(name: str, context: Optional[Mapping[str, Any]] = None) -> str
Render a template and return the text.
name is the template's path in the folder.
context is a dict (or any mapping) of the template's variables.
response ¶
response(name: str, context: Optional[Mapping[str, Any]] = None, /, *, status: int = 200, headers: HeaderItems = ()) -> Response
Render a template now and return it as an HTML response.
name is the template's path in the folder.
context is a dict (or any mapping) of the template's variables.
status is the HTTP status code.
headers are extra headers; a Content-Type in them wins.
views.response("post.html", {"post": post})
Guide: https://3d3n-pyc.github.io/korvex/templates/
Markup ¶
Text known to be safe HTML, so escaping leaves it as is; any str operation on it gives a plain str.
TemplateError ¶
Base class of every template error.
TemplateSyntaxError ¶
TemplateSyntaxError(message: str, name: str, line: int)
The template is invalid; str() reads name, line N: message.
UndefinedError ¶
A template used a name, key or attribute that does not exist.