How to send multiple input field values with same name?

这一生的挚爱 提交于 2019-12-20 09:38:33

问题


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

<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?


回答1:


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:

relations = request.POST.getlist('relations')



回答2:


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:


this generate a list, you can manipulate in for

request.POST.getlist('relations')


来源:https://stackoverflow.com/questions/478382/how-to-send-multiple-input-field-values-with-same-name

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!