Things on this page are fragmentary and immature notes/thoughts of the author. Please read with your own judgement!
** Things on this page are fragmentary and immature notes/thoughts of the author. Please read with your own judgement! **
!pip3 install jinja2Requirement already satisfied: jinja2 in /usr/local/lib/python3.8/site-packages (2.11.2)
Requirement already satisfied: MarkupSafe>=0.23 in /usr/local/lib/python3.8/site-packages (from jinja2) (1.1.1)
from jinja2 import Template
from argparse import Namespacetemplate = Template("Hello {{ name }}!")
template.render(name="John Doe")'Hello John Doe!'s = """<title>{% block title %}{% endblock %}</title>
<ul>
{% for user in users %}
<li><a href="{{ user.url }}">{{ user.username }}</a></li>
{% endfor %}
</ul>
"""
s = Template(s).render(users=[Namespace(username="Ben", url="www.legendu.net")])
print(s)<title></title>
<ul>
<li><a href="www.legendu.net">Ben</a></li>
</ul>