Get multiple request params of the same name

前端 未结 4 972
醉话见心
醉话见心 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:56

    You can use getlist, which is similar to Django's getList but for some reason isn't mentioned in the Flask documentation:

    return str(request.args.getlist('param'))
    

    The result is:

    [u'a', u'bbb']
    

    Use request.args if the param is in the query string (as in the question), request.form if the values come from multiple form inputs with the same name. request.values combines both, but should normally be avoided for the more specific collection.

提交回复
热议问题