Django 提供了一些 Django 特定的异常以及许多 Python 异常。
DoesNotExist
¶ObjectDoesNotExist
¶DoesNotExist
当一个给定参数的查询未能发现对象时抛出该异常。
ObjectDoesNotExist
定义在 django.core.exceptions
中。
DoesNotExist
是基类 ObjectDoesNotExist
异常的子类,
用于提供对每一个模型类作为一种识别对象未能发现的特定类型的一种方式。
请查看 get()
获取
ObjectDoesNotExist
和 DoesNotExist
的更多信息。
MultipleObjectsReturned
¶MultipleObjectsReturned
当预期仅返回一个对象的查询确返回多个是抛出的异常。
该异常的基础版本由 django.core.exceptions
提供;每个模型类都
包含一个子类版本用于识别返回多个对象的特定对象类型。
请查看 get()
获取更多信息。
SuspiciousOperation
¶SuspiciousOperation
当用户执行的操作,从安全的角度来看被视为可疑时抛出的异常,例如篡改一个会话 cookie 。
PermissionDenied
¶PermissionDenied
当用户没有权限来执行所请求的操作时抛出的异常。
ViewDoesNotExist
¶ViewDoesNotExist
当一个请求的视图不存在时由
django.core.urlresolvers
抛出的异常。
MiddlewareNotUsed
¶MiddlewareNotUsed
当一个中间件在当前服务器配置中不能使用时抛出的异常。
ImproperlyConfigured
¶ImproperlyConfigured
当 Django 的某种配置错误时抛出的异常
– 例如 settings.py
中的值错误或不可解析。
FieldError
¶FieldError
当一个模型字段有问题是抛出的异常。
发生这种情况的原因有几个:
ValidationError
¶The ValidationError
exception is raised when data fails form or
model field validation. For more information about validation, see
Form and Field Validation,
Model Field Validation and the
Validator Reference.
NoReverseMatch
¶The NoReverseMatch
exception is raised by
django.core.urlresolvers
when a matching URL in your URLconf
cannot be identified based on the parameters supplied.
Django wraps the standard database exceptions DatabaseError
and
IntegrityError
so that your Django code has a guaranteed common
implementation of these classes. These database exceptions are
provided in django.db
.
DatabaseError
¶IntegrityError
¶The Django wrappers for database exceptions behave exactly the same as the underlying database exceptions. See PEP 249, the Python Database API Specification v2.0, for further information.
models.
ProtectedError
¶Raised to prevent deletion of referenced objects when using
django.db.models.PROTECT
. Subclass of IntegrityError
.
UnreadablePostError
¶The UnreadablePostError
is raised when a user cancels an upload.
It is available from django.http
.
TransactionManagementError
¶The TransactionManagementError
is raised for any and all problems
related to database transactions. It is available from
django.db.transaction
.
Django raises built-in Python exceptions when appropriate as well. See the
Python documentation for further information on the
built-in exceptions
.
Oct 01, 2017