【发布时间】:2016-02-18 00:44:17
【问题描述】:
如何以 POST 形式发送列表/数组并使用滤锅对其进行解码?我已经尝试了几种方法,但到目前为止没有运气。使用如下形式的表单和滤锅架构将引发错误:[1,2,3] is not iterable
example_1.html:
<form action="path_to_page" method="post">
<input name="ids" type="text" value="[1,2,3]">
<input type="submit">
</form>
example_1.py:
class IDList(colander.List):
item = colander.SchemaNode(colander.Integer())
class IDS(colander.MappingSchema):
ids = colander.SchemaNode(IDList())
而这种其他方法根本行不通,因为我们无法创建名为 ids[] 的漏勺节点。
example_2.html:
<form action="path_to_page" method="post">
<input name="ids[]" type="text" value="1">
<input name="ids[]" type="text" value="2">
<input name="ids[]" type="text" value="3">
<input type="submit">
</form>
有没有办法做到这一点?
【问题讨论】: