1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
|
from minijinja import Environment
INDEX = """{% extends "layout.html" %}
{% block title %}{{ page.title }}{% endblock %}
{% block body %}
<ul>
{%- for item in items %}
<li>{{ item }}
{%- endfor %}
</ul>
{% endblock %}
"""
LAYOUT = """<!doctype html>
<title>{% block title %}{% endblock %}</title>
<body>
{% block body %}{% endblock %}
</body>
"""
env = Environment(templates={
"index.html": INDEX,
"layout.html": LAYOUT,
})
print(env.render_template(
'index.html',
page={"title": "The Page Title"},
items=["Peter", "Paul", "Mary"]
))
|