如何发送具有相同名称的多个输入字段值? [英] How to send multiple input field values with same name?

查看:21
本文介绍了如何发送具有相同名称的多个输入字段值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有 m2m 字段,假设它有名称关系",所以我希望允许用户发送任意数量的关系.我使用同名的javascript向html添加新输入,就像这样

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' />

在cleaned_data 中,我只收到第二个输入('b')的值.如何同时接收?

in cleaned_data i receive only value of second input ('b'). How to receive both?

推荐答案

我不知道如何使用 Forms 做到这一点,但如果您想以原始方式获取值,我会这样做:

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆