How to send multiple input field values with same name?

前端 未结 3 1254
执念已碎
执念已碎 2020-12-28 09:01

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,

相关标签:
3条回答
  • 2020-12-28 09:14

    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.

    0 讨论(0)
  • 2020-12-28 09:36

    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')
    
    0 讨论(0)
  • 2020-12-28 09:37

    this generate a list, you can manipulate in for

    request.POST.getlist('relations')
    
    0 讨论(0)
提交回复
热议问题