【发布时间】:2013-12-27 16:06:07
【问题描述】:
一点背景知识,它的后端应该接收一个表单,然后根据来自发布数据的过滤器填充一个新列表。
假设我有这样的标记
<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 声明。例如,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
那么如何处理呢?
【问题讨论】:
-
我不明白你的问题。你能让你的例子更清楚吗?比如,用户选择“Painting Composition”和“Game Design”,我希望我的视图能够获取变量“x”来存储...的列表使用实际的示例值您对结果中所需内容的描述。
标签: python html python-2.7 flask