标签:def jinja2 html code coding read enc dex template
后端代码
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>
标签:def jinja2 html code coding read enc dex template
原文地址:https://www.cnblogs.com/EdenWu/p/14697427.html