flask用 render_template()函数渲染前端页面
from flask import Flask,render_template
app=Flask(__name__)
@app.route('/')
def index():
return render_template('index.html')
if __name__=='__main__':
app.run()
视图函数传参数给html页面
@app.route('/hobby')
def show_hobby():
myhobby=['听音乐','写代码','玩游戏']
return render_template('hobbys.html',hobbyList=myhobby)
<body>
<h2>我的兴趣爱好有:</h2>
<ul>
{% for hobby in hobbyList %}
<li>{{ hobby }}</li>
{% endfor %}
</ul>
</body>
标签:__,render,flask,app,JinJa2,template,hobby,模板
From: https://www.cnblogs.com/unity-yancy/p/17220509.html