In python, I am currently doing this:
if user_can_read(request.user, b) == False:
Is there any other way of checking if the function returns False
?
If you want to check that a variable is explicitly True or False (and is not truthy/falsy), use is ( if variable is True ). If you want to check if a variable is equal to 0 or if a list is empty, use if variable == 0 or if variable == [] .
If user_can_read returns anything (except 0, False, etc), it will be considered True, and do stuff.
Use the IF function along with AND, OR and NOT to perform multiple evaluations if conditions are True or False. The condition you want to test. The value that you want returned if the result of logical_test is TRUE. The value that you want returned if the result of logical_test is FALSE.
Python bool() function is used to return or convert a value to a Boolean value i.e., True or False, using the standard truth testing procedure.
You could just use
if user_can_read(request.user, b): ## do stuff
If user_can_read
returns anything (except 0, False, etc), it will be considered True, and do stuff.
And the negation: if not user_can_read(request.user, b)
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