【发布时间】:2014-02-13 21:08:11
【问题描述】:
在烧瓶 jinja2 模板中的多个列表上迭代 for loop 时遇到问题。
我的代码如下所示
Type = 'RS'
IDs = ['1001','1002']
msgs = ['Success','Success']
rcs = ['0','1']
return render_template('form_result.html',type=type,IDs=IDs,msgs=msgs,rcs=rcs)
到目前为止,我不确定是否能找到正确的模板,
<html>
<head>
<title>Response</title>
</head>
<body>
<h1>Type - {{Type}}!</h1>
{% for reqID,msg,rc in reqIDs,msgs,rcs %}
<h1>ID - {{ID}}</h1>
{% if rc %}
<h1>Status - {{msg}}!</h1>
{% else %}
<h1> Failed </h1>
{% endif %}
{% endfor %}
</body>
</html>
我想要得到的输出类似于下面的 html 页面
Type - RS
ID - 1001
Status - Failed
ID - 1002
Status - Success
【问题讨论】:
-
你需要使用zip()
-
@KobiK 这也是我的第一个猜测......它抛出错误 UndefinedError: 'zip' is undefined