You can define an initial value when using get
on dict
. Using this feature you can remove checking for None
because if the value is not present in the request.form
it will initiate it with the empty string (
).
After that you can check for either of the variables like below:
parameterA = request.form.get('parameterA','')
parameterB = request.form.get('parameterB','')
#if both of them are '' then you don't have any of them and it raises error
#if none of them are '' then you have both of them and it raises error
if (parameterA == '' and parameterB == '') or (parameterA != '' and parameterB != '') :
print('Parameter A and B are not suitable')
Another fun way:
if ['',''] == [parameterA, parameterB] or not ('' in [parameterA, parameterB]) :
print('Parameter A and B are not suitable')
First one checks for both empty value and the second one checks for the both passed.