后端代码
from jinja2 import Template
def index():
with open('./index.html', 'r', encoding='utf-8') as fp:
template = Template(fp.read())
ret = template.render({'name':'张三', 'hobby':['打牌', '打球']})
data = ret.encode()
return data
前端代码
<h1>{{ name }}}</h1>
<ul>
{% for i in hobby %}
<li>{{ i }}</li>
{% endfor %}
</ul>