Get multiple request params of the same name

前端 未结 4 964
醉话见心
醉话见心 2020-11-30 06:10

My problem is that with the given code:

from flask import Flask, request

app = Flask(__name__)

@app.route(\"/\")
def hello():
    return str(request.values         


        
4条回答
  •  攒了一身酷
    2020-11-30 06:45

    If you used $('form').serialize() in jQuery to encode your form data, you can use request.form['name'] to get data, but note that when multiple input elements' names are the same, request.form['name'] will only get the first matched item. So I checked the form object from the Flask API, and I found this. Then I checked the MultiDict object, and I found the function getlist('name').

    If there are multiple inputs with the same name, try this method: request.form.getlist('name')

提交回复
热议问题