Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 375
nimeshkiranverma Avatar asked Jul 11 '12 04:07

nimeshkiranverma


2 Answers

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.

like image 54
Ismail Badawi Avatar answered Nov 14 '22 22:11

Ismail Badawi


is None used for == null and is not None used for !=null

like image 40
Vishal Patel Avatar answered Nov 14 '22 22:11

Vishal Patel