Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get raw query string in flask

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?

like image 467
Charlie Andrews Avatar asked Jun 13 '13 17:06

Charlie Andrews


2 Answers

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'
like image 53
icecrime Avatar answered Sep 17 '22 22:09

icecrime


request.query_string also seems to work.

like image 30
vovel Avatar answered Sep 19 '22 22:09

vovel