一点背景,后端应接收表单,然后根据帖子数据中的过滤器填充新列表。
假设我有这样的标记
<form method="POST" action="/my/app/route/">
<table>
<tr>
<td>
Name:
</td>
<td>
<input type="text" name="NAME" maxlength="100" size="20" style="width: 90%;"
</td>
</tr>
<tr>
<td>
Classes:
</td>
<td>
<select multiple="true" name="CLASSES">
<option>Painting Composition</option>
<option>Analysis of Algorithms</option>
<option>Game Design</option>
<option>Assembly Language</option>
<option>Pirate History</option>
</select>
</td>
</tr>
</table>
</form>
这将显示为文本框和选择框。现在在我的烧瓶中,我想要区别对待文本框和选择框;如果某些内容来自文本框,我只想做一个in
语句。 EG,if (textbox): if row[k] not in filter_dict[k]: break
@app.route('/my/app/route/')
def filter_CSV(data):
filter_dict = dict(request.form)
return_list = []
#row looks like this: {"NAME": string, "CLASSES": string}
for row in data:
for k, v in filter_dict.iteritems():
# here is where the check for text box would come
# else, do this stuff:
row[k] = row[k].split(', ')
if not set(row[k]).issuperset(set(filter_dict[k])):
break
return_list.append(row)
return return_list
那怎么会这样呢?
答案 0 :(得分:0)
Take a look here at the Flask request object.
您不需要像往常一样将对象放入字典中。您只需访问NAME:request.form ['NAME']