如何获取django中的复选框值? [英] how to get checkbox value in django?
问题描述
<tr name="item">
<td><input type="checkbox" ></td>
<td>>{{ foo }}</td>
<td> {{ bar }} </td>
</tr>
现在我想要在django视图中 request.POST.getlist('item ')
返回值 foo
和 bar
的值。但是它返回null。
Now I want that in django views request.POST.getlist('item')
returns the value of ie foo
and bar
. But it is returning null.
推荐答案
我不知道你所问的一切,但如果你想得到foo 和bar当用户提交表单时,您将不得不将其添加到隐藏或文本框中的表单元素(取决于用户是否可以修改它们)。
I'm not sure to understand everything you asked, but if you want to get "foo" and "bar" when the user submit the form, you will have to add them in a form element like hidden or textfields (depending on if the user can modify them or not).
当您提交表单时,服务器将永远不会收到整个DOM。
The server will never receive the whole DOM when you submit a form.
此外,您必须找到一种方式来指示哪个复选框属于foo& ; bar。
Also, you will have to find a way to indicate on which checkbox belongs foo & bar.
这篇关于如何获取django中的复选框值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!