我正在使用 Django 1.7。通常你可以在你的模型上捕获 DoesNotExist
异常;
try:
...
except model.DoesNotExist, den:
...
我想捕获任何 DoesNotExist
异常。我真的不想关心它的模型。实际上,我也真的不知道 DoesNotExist
是通过哪个模型通过代码段的。我的意思是,我不知道模型。
所以我必须以某种方式捕获任何 DoesNotExist
错误。
有没有办法在 Django
中捕获任何 DoesNotExist
错误?
最佳答案
DoesNotExist
异常是 django.core.exceptions.ObjectDoesNotExist
的子类:
from django.core.exceptions import ObjectDoesNotExist
try:
# ...
except ObjectDoesNotExist as den:
# handle exception
关于python - 捕获任何 DoesNotExist 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25928990/