I am using this code
except MultipleObjectsReturned:
return HttpResponse('some error')
but i get this error
global name 'MultipleObjectsReturned' is not defined
You can do either:
from django.core.exceptions import MultipleObjectsReturned
except MultipleObjectsReturned as e:
return HttpResponse(e)
Or:
except yourmodel.MultipleObjectsReturned as e:
return HttpResponse(e)
https://docs.djangoproject.com/en/1.3/ref/exceptions/#django.core.exceptions.MultipleObjectsReturned
A base version of this exception is provided in
django.core.exceptions; each model class contains a subclassed version that can be used to identify the specific object type that has returned multiple objects.
from django.core.exceptions import MultipleObjectsReturned
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With