Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/75.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Django:从html表单获取列表_Python_Html_Django_List - Fatal编程技术网

Python Django:从html表单获取列表

Python Django:从html表单获取列表,python,html,django,list,Python,Html,Django,List,这是我的django代码 def postData(request): itemQuantity = request.POST.getlist('itemQuantity') print itemQuantity 下面是我的html代码 <form action="/test/data/" method="POST"> <input type="hidden" name="itemQuantity" id="" style="width:350px;" val

这是我的django代码

def postData(request):
    itemQuantity = request.POST.getlist('itemQuantity')
    print itemQuantity
下面是我的html代码

<form action="/test/data/" method="POST">
<input type="hidden" name="itemQuantity" id="" style="width:350px;" value="{{itemQuantity}}">
<center><input type="submit" style="background-color:#00B16A; padding: 4px; color: #FFF; font-weight: bold; border: 1px solid #999; margin-top:5px;" value="Login"></center>
</form>
预期产量为

[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6]

我不想听起来像Alex Trebec,但这似乎不是一个问题。我可以知道在表单中包含隐藏的itemQuantity列表的目的吗?看起来你正在将列表放入列表中-输入的是什么类型的模型字段
{{itemQuantity}
?您是否尝试过常规的
请求.POST.get('itemQuantity'或None)
?是的。HTML表单返回字符串。如果希望这些字符串是整数,则需要将其内容转换为整数(同时也要准备好,无论您多么坚持,表单返回的内容都可能不是整数)。
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6]