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

22,944

Solution 1

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.

Solution 2

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

Share:
22,944
nimeshkiranverma
Author by

nimeshkiranverma

Entrepreneur Passionate Programmer Open Source Enthusiast Ex Linkedin Employee Artist IIT Delhi Alumnus Studied Maths and Computing for 5 years Love to collaborate and provide a helping hand Presently pursuing a Fin-Tech venture Linkedin: https://www.linkedin.com/in/nimeshkverma/ Gmail: [email protected]

Updated on March 19, 2020

Comments

  • nimeshkiranverma
    nimeshkiranverma about 4 years

    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.