您的位置:首页 > 编程语言 > Python开发

python的一些总结4

2015-08-04 13:49 651 查看
这篇继续水 但是在水的的基础上 让搭建能正常使用flask 搭建一个站

上篇讲到在 模板view中 输入{{xx }} 可以打印 后台传的值。 这篇讲一下 循环控制 条件控制等

修改后台代码:

@app.route('/')
def hello_world():
#return 'Hello World!'
#return jsonify({'key':'hello'}) #返回json
#return render_template_string('<html><head></head><body>1111:{{test}}</body></html>',test="tttt") #通过拼接字符串方式
return render_template('index.html', test="tttttt",alist=[1,2,3,4,5,6]) #普通返回 view 方式


修改前台代码:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>

{{ test }}

{# 这是注释的写法 #}
{# 下面是 for 的写法  #}
{% for n in alist %}
{% if n >3 %}
{{ n }}
{% endif %}
{% endfor %}

</body>
</html>


注: for if 等表达式 需要用{% %} 注释 需要使用{# #}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: