[Django]-Handle variable that could be None

6πŸ‘

βœ…

In the general case of checking if something is None.. just check it?

if x is not None and x.is_valid():
   ...

In Python, or and and both short circuit, meaning that in the expression x and y, y is not evaluated if x is false (since the expression is false no matter what y is).

πŸ‘€Brendan Long

Leave a comment