开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜