How do you get a query string on Flask?

Tampa picture Tampa · Aug 2, 2012 · Viewed 374.5k times · Source

Not obvious from the flask documention on how to get the query string. I am new, looked at the docs, could not find!

So

@app.route('/')
@app.route('/data')
def data():
    query_string=??????
    return render_template("data.html")

Answer

Kracekumar picture Kracekumar · Aug 2, 2012
from flask import request

@app.route('/data')
def data():
    # here we want to get the value of user (i.e. ?user=some-value)
    user = request.args.get('user')