【发布时间】:2017-03-06 21:05:46
【问题描述】:
我正在尝试使用 BooleanField() 在 json 文件中生成 html 表中的清单到目前为止,我没有使用 wtforms:
来自 view.py
from app import app
from flask import render_template
json_data = [{'Description':'Red', 'id':'f1'},{'Description':'Green', 'id':'f2'},{'Description':'Blue', 'id':'f3'}]
@app.route('/taggs', methods = ['GET', 'POST'])
def taggs()
return render_template('taggs.html', jdata = json_data)
来自 taggs.html
<form role="form" method= "post">
<table id='ctable'>
<thead>
<tr>
<th data-field="Description"></th>
<th data-field="Selection"></th>
</tr>
</thead>
<tbody>
</tbody>
{% for i in jdata %}
<tr>
<td>{{ i.Description }}</td>
<td><input type ="checkbox" id = "{{ i.id }}"></td>
</tr>
{% end for%}
</table>
</form>
有没有办法使用 wtforms 中的列表生成表单字段?还是我必须创建一个类并声明列表中的每个变量?
【问题讨论】:
标签: python html flask flask-wtforms