Is there a way to get the raw query string or a list of query string parameters in Flask?
I know how to get query string parameters with request.args.get('key')
, but I would like to be able to take in variable query strings and process them myself. Is this possible?
There are several request
attributes that let you access the raw url:
Imagine your application is listening on the following URL:
http://www.example.com/myapplication
And a user requests the following URL:
http://www.example.com/myapplication/page.html?x=y
In this case the values of the above mentioned attributes would be the following:
path /page.html script_root /myapplication base_url http://www.example.com/myapplication/page.html url http://www.example.com/myapplication/page.html?x=y url_root http://www.example.com/myapplication/
These, eventually with the help of urlparse
, will let you extract the information you need:
>>> from urlparse import urlparse
>>> urlparse(request.url).query
'x=y'
request.query_string also seems to work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With