Get multiple request params of the same name

前端 未结 4 965
醉话见心
醉话见心 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 07:01

    Another option is to use a flat json structure with request.args. Because sometimes you simply do not know the parameter beforehand and you cannot use .getlist().

    arguments = request.args.to_dict(flat=False)
    
    # Get a specific parameter
    params = arguments.get('param')
    print(params)
    
    # Get all the parameters that have more than one value
    for field, values in arguments.items():
        if len(values) > 1:
            print(values)
    

提交回复
热议问题