Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flask request.args.get get all params (Python)

Tags:

python

flask

get

how i can parse all GET params from URL in flask? I tried use request.args.get, but it works with specific GET params (pre defined), but i need parse it all from my large URL (ex: http://site.ru/?a=1&b=2&c=3&some_string=string...)

like image 356
Konstantin Rusanov Avatar asked Dec 19 '16 19:12

Konstantin Rusanov


People also ask

How do you get parameters from request in Flask?

In the first one we would use request. args. get('<argument name>') where request is the instance of the class request imported from Flask. Args is the module under which the module GET is present which will enable the retrieve of the parameters.

What is args get?

The args attribute is a dictionary containing arguments from the URL. The get() method is a built-in dictionary method that will “get” an item from a dictionary or return a default value ( None if key not found). In this case, it avoids a KeyError if “name” argument not found.

What is args in Flask?

request.args is a MultiDict with the parsed contents of the query string. From the documentation of get method: get(key, default=None, type=None) Return the default value if the requested data doesn't exist.

How do you pass a parameter in a python query?

To send parameters in URL, write all parameter key:value pairs to a dictionary and send them as params argument to any of the GET, POST, PUT, HEAD, DELETE or OPTIONS request. then https://somewebsite.com/?param1=value1&param2=value2 would be our final url.


1 Answers

If you use request.args it will provide a dictonary with key-value pairs of the GET parameters

Ex: http://website.com/index?arg1=hello&arg2=world

print request.args
>> {"arg1": "hello", "arg2": "world"}

The request.args.get(key) is a useful dictionary function that will return None if the parameter is not set rather than raising a KeyError

like image 94
Mike Avatar answered Oct 11 '22 06:10

Mike