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 an optional parameter or not.
Flask documentation didn't help much.
You can actually use the default value,
opt_param = request.args.get("something")
if opt_param is None:
print "Argument not provided"
A more Pythonic way to do the same would be using the in
operator:
if 'varname' in request.args:
# parameter 'varname' is specified
varname = request.args.get('varname')
else:
# parameter 'varname' is NOT specified
You can check it with this code:
name = request.args.get("name", default=None, type=str)