How do you access the query string in Flask routes?
The full URL is available as
request.url, and the query string is available as
Here's an example:
from flask import requestdef adhoc_test(): return request.query_string
To access an individual known param passed in the query string, you can use
request.args.get('param'). This is the "right" way to do it, as far as I know.
ETA: Before you go further, you should ask yourself why you want the query string. I've never had to pull in the raw string - Flask has mechanisms for accessing it in an abstracted way. You should use those unless you have a compelling reason not to.
I came here looking for the query string, not how to get values from the query string.
request.query_string returns the URL parameters as raw byte string (Ref 1).
Example of using
from flask import Flask, requestapp = Flask(__name__)def get_query_string(): return request.query_stringif __name__ == '__main__': app.run(debug=True)