Templates

A real template engine โ€” autoescaping, inheritance, and filters โ€” with no dependency on Jinja.

Syntax

{{ value }}                     class=com># auto HTML-escaped
{{ value | safe }}              class=com># raw (unescaped)
{{ price | currency }}          class=com># filters
{% if user %}hi{% else %}...{% endif %}
{% for p in posts %}{{ p.title }}{% endfor %}
{% set total = a + b %}
{% include "partial.html" %}

Inheritance

base.html:

<title>{% block title %}Site{% endblock %}</title>
<main>{% block main %}{% endblock %}</main>

A child template overrides blocks:

{% extends "base.html" %}
{% block title %}Home{% endblock %}
{% block main %}<h1>Hello {{ name }}</h1>{% endblock %}

Filters

upperlowertitle capitalizetrimlength default(x)currencydate(fmt) join(sep)round(n)truncate(n) safe

From your app

app.use_templates("templates")           class=com># a directory of .html files
@app.get("/")
class=kw>def home(req):
    class=kw>return app.render("home.html", name="Ada")
See examples/blog.py for inheritance + filters in a real app.