如果 URL 的查询字符串具有多值参数,如 ?name=a&name=b flask 中的第二个值发生了什么?

If the query string of URL has multi-value parameters like ?name=a&name=b what happened to the second value in flask?

如果 URL 的查询字符串具有多值参数,例如 /obj?name=a&name=b 那么第二个值发生了什么变化?默认情况下,Flask 假定查询参数是单值的。

从 JSON 个对象返回的参数示例: obj=[{"name"="a","class"="x"},{"name"="b","class"="y"},{"name "="c","class"="z"}}

那么 request.args.to_dict() 返回的值是: {"name"="a","class"="x"}

第二个值怎么了? 所需的输出是:

{"name"="a","class"="x"},{"name"="b","class"="y"}

@app.route('/obj', methods=['GET'])
def api_name():
    # Check if a name was provided as part of the URL.
    # If the name is provided, assign it to a variable.
    # If no name is provided, display an error in the browser.
    
    if 'name' in request.args:
        name = request.args['name'])
    else:
        return "Error: No name field provided. Please specify an name."

    # Create an empty list for our results
    results = []

    # Loop through the data and match results that fit the requested name.
    # name's are unique, but other fields might return many results
    for n in obj:
        if n['name'] == name:
            results.append(n)

    # Use the jsonify function from Flask to convert our list of
    # Python dictionaries to the JSON format.
    return jsonify(results)
# Get a specific parameter
params=request.args.getlist('name')

它将参数转换为列表,在本例中为 params=['a','b']