Skip to content Skip to sidebar Skip to footer

How To Process GET Query String With Flask

How do I process a long GET request with Flask? Is is possible to get a dictionary all the params? Here is the query string I'm trying to parse: /?msisdn=19150000001&to=121080

Solution 1:

if you want to convert the query string (MultiDict to normal dict)

from flask import Flask, jsonify, request

app = Flask(__name__)

@app.route("/")
def hello():
    all_args = request.args.to_dict()
    return jsonify(all_args)

Solution 2:

Yes. request.args is a MultiDict:

from flask import Flask, jsonify, request

app = Flask(__name__)

@app.route("/")
def hello():
    all_args = request.args.lists()
    return jsonify(all_args)

Post a Comment for "How To Process GET Query String With Flask"