Search code examples
pythondjangovalidationviewnull

How to check that the data is 'null' in django view?


I have a small validation to do in my view,i have to check whether the data received from the data field (for which'null'=true) of the form is null or not. Presently i did this by

if data_received == None :
                    "some task"

and i got what i wanted. My question is Is this code optimum or there is some better way to do the same.


Solution

  • That's pretty much as good as it's going to get. You typically want to use is None instead of == None just in case the left hand side is an instance of a class which has defined == to mean something special when used with None, but it's not a big deal here.