I have m2m field, lets say it have name 'relations', so i want to allow user to send as many relations as he wants. I add new input to html with javascript with same name, like so
我有m2m字段,让我们说它有名称'关系',所以我想让用户发送尽可能多的关系。我使用相同名称的javascript向html添加新输入,就像这样
<input type='text' name='relations' value='a' />
<input type='text' name='relations' value='b' />
in cleaned_data i receive only value of second input ('b'). How to receive both?
在cleaning_data中,我只收到第二个输入值('b')。怎么收到?
3 个解决方案
#1
24
I don't know how to do that with Forms, but if you want to grab the values in the raw way, here's how I'd do:
我不知道如何使用Forms,但如果你想以原始方式获取值,这就是我的方法:
relations = request.POST.getlist('relations')
#2
4
You don't need to grab all the raw values, you can just get the specific data by using element name like this:
您不需要获取所有原始值,您可以使用元素名称来获取特定数据,如下所示:
relations = request.form.getlist('relations')
That will return a list of values in the relations
input.
这将返回关系输入中的值列表。
#3
1
this generate a list, you can manipulate in for
这会生成一个列表,你可以操纵
request.POST.getlist('relations')
#1
24
I don't know how to do that with Forms, but if you want to grab the values in the raw way, here's how I'd do:
我不知道如何使用Forms,但如果你想以原始方式获取值,这就是我的方法:
relations = request.POST.getlist('relations')
#2
4
You don't need to grab all the raw values, you can just get the specific data by using element name like this:
您不需要获取所有原始值,您可以使用元素名称来获取特定数据,如下所示:
relations = request.form.getlist('relations')
That will return a list of values in the relations
input.
这将返回关系输入中的值列表。
#3
1
this generate a list, you can manipulate in for
这会生成一个列表,你可以操纵
request.POST.getlist('relations')