How do I import the Django DoesNotExist exception?

You can also import ObjectDoesNotExist from django.core.exceptions, if you want a generic, model-independent way to catch the exception:

from django.core.exceptions import ObjectDoesNotExist

try:
    SomeModel.objects.get(pk=1)
except ObjectDoesNotExist:
    print 'Does Not Exist!'

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)