Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check for the existence of a get parameter in flask

Tags:

python

flask

I'm new to python and flask.

I know that I can fetch a GET parameter with request.args.get(varname);. I wanted to check whether a GET request to my server is specifying and optional parameter or not.

Flask documentation didn't helped much.

like image 915
Thomas Abraham Avatar asked Jan 09 '13 11:01

Thomas Abraham


People also ask

How do you access parameters on a 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.

CAN GET method have query parameters?

When the GET request method is used, if a client uses the HTTP protocol on a web server to request a certain resource, the client sends the server certain GET parameters through the requested URL. These parameters are pairs of names and their corresponding values, so-called name-value pairs.

What is request args get 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.


1 Answers

You can actually use the default value,

opt_param = request.args.get("something") if opt_param is None:     print "Argument not provided" 
like image 124
Jakob Bowyer Avatar answered Oct 07 '22 01:10

Jakob Bowyer