When I ask the model manager to get an object, it raises DoesNotExist when there is no matching object.
go = Content.objects.get(name=\"baby\")
We can use Django builtin exception which attached to the models named as .DoesNotExist. So, we don't have to import ObjectDoesNotExist exception.
Instead doing:
from django.core.exceptions import ObjectDoesNotExist
try:
content = Content.objects.get(name="baby")
except ObjectDoesNotExist:
content = None
We can do this:
try:
content = Content.objects.get(name="baby")
except Content.DoesNotExist:
content = None