一、控制语句
1.1 if语句
@app.route('/user')
def user():
user = 'dongGe'
return render_template('user.html',user=user)
<html>
<head>
{% if user %}
<title> hello {
{user}} </title>
{% else %}
<title> welcome to flask </title>
{% endif %}
</head>
<body>
<h1>hello world</h1>
</body>
</html>
1.2 for循环语句
@app.route('/loop')
def loop():
fruit = ['apple','orange','pear','grape']
return render_template('loop.html',fruit=fruit)
<html>

本文介绍了Jinja2模板中的控制语句,包括if语句和for循环,接着详细讲解了Flask中处理Web表单的方法,特别是使用WTForms及其验证器进行数据采集和验证的过程。此外,提到了配置Flask-WTF时的SECRET_KEY参数对于CSRF保护的重要性。
最低0.47元/天 解锁文章
871

被折叠的 条评论
为什么被折叠?



