如何发送同名的多个输入字段值? [英] How to send multiple input field values with same name?
本文介绍了如何发送同名的多个输入字段值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
< input type ='text'name ='relations 'value ='a'/>
< input type ='text'name ='relationships'value ='b'/>在clean_data中
我只接收第二个输入('b')的值。如何收到这两个?
解决方案
我不知道如何使用Forms,但如果你想抓住值以原始方式,我将如何做:
relations = request.POST.getlist('relations')
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?
解决方案
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')
这篇关于如何发送同名的多个输入字段值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文