MultipleHiddenInput不能通过POST正确编码?

时间:2010-04-23 19:09:22

标签: django django-forms

表单看起来很简单:

class MyForm(forms.Form):
    ids = forms.MultipleChoiceField(widget=forms.MultipleHiddenInput())


def view(request):
  ...
  form = MyForm(initial={'ids': [o.id for o in queryset]})

它给了我HTML(看起来很好):

<form method="post" action="/foo/bar/">
<input type="hidden" name="ids" value="7720889" id="id_ids_0">
<input type="hidden" name="ids" value="7717962" id="id_ids_1">
<input type="hidden" name="ids" value="7717807" id="id_ids_2">
<input type="hidden" name="ids" value="7713584" id="id_ids_3">
<input type="hidden" name="ids" value="7712277" id="id_ids_4">
<input type="hidden" name="ids" value="7707475" id="id_ids_5">
<input type="hidden" name="ids" value="7707257" id="id_ids_6">
<input type="hidden" name="ids" value="7705271" id="id_ids_7">
<input type="hidden" name="ids" value="7704338" id="id_ids_8">
<input type="hidden" name="ids" value="7704137" id="id_ids_9">
<input type="hidden" name="ids" value="7695444" id="id_ids_10">
<input type="hidden" name="ids" value="7695242" id="id_ids_11">
<input type="hidden" name="ids" value="7690683" id="id_ids_12">
<input type="hidden" name="ids" value="7690431" id="id_ids_13">
<input type="hidden" name="ids" value="7689035" id="id_ids_14">
<input type="hidden" name="ids" value="7681230" id="id_ids_15">
<input type="hidden" name="ids" value="7679189" id="id_ids_16">
<input type="hidden" name="ids" value="7675315" id="id_ids_17">
<input type="hidden" name="ids" value="7667291" id="id_ids_18">
<input type="hidden" name="ids" value="7661162" id="id_ids_19">
<button type="submit">Test</button>
</form>

但是,在进入的POST中,我只得到一个值:

<QueryDict: {u'ids': [u'7661162']}>

是什么给出的?我做错了什么?

1 个答案:

答案 0 :(得分:4)

我相信你想要request.POST.getlist('ids'),它应该返回为id设置的所有值的列表。