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.
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.
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.
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.
You can actually use the default value,
opt_param = request.args.get("something") if opt_param is None: print "Argument not provided"
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