Abdul Rehman Abdul Rehman - 5 months ago 13
Python Question

Object.get() throws exception if Nothing is found

Is there a possibility to return none if no results are found by a

function call?
I know it throws an exception by default, but I want to return none from it.


You can do it with exceptions like:

     object = Model.objects.get(foo='bar') 
 except Model.DoesNotExist:    
     object = None