开发者

Which file is used in import statement for 'MultipleObjectsReturne' exception

开发者 https://www.devze.com 2023-03-18 19:51 出处:网络
I am using this code except MultipleObjectsReturned: return HttpResponse(\'some error\') 开发者_如何学Python

I am using this code

except MultipleObjectsReturned:
    return HttpResponse('some error')
开发者_如何学Python

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
0

精彩评论

暂无评论...
验证码 换一张
取 消