8
Django raises some Django specific exceptions as well as many standard
11
Django-specific Exceptions
12
==========================
14
.. module:: django.core.exceptions
15
:synopsis: Django specific exceptions
17
ObjectDoesNotExist and DoesNotExist
18
-----------------------------------
20
The ``DoesNotExist`` exception is raised when an object is not found
21
for the given parameters of a query.
23
``ObjectDoesNotExist`` is defined in ``django.core.exceptions``.
24
``DoesNotExist`` is a subclass of the base ``ObjectDoesNotExist``
25
exception that is provided on every model class as a way of
26
identifying the specific type of object that could not be found.
28
See :meth:`~django.db.models.QuerySet.get()` for further information
29
on ``ObjectDoesNotExist`` and ``DoesNotExist``.
31
MultipleObjectsReturned
32
-----------------------
34
The ``MultipleObjectsReturned`` exception is raised by a query if only
35
one object is expected, but multiple objects are returned. A base version
36
of this exception is provided in ``django.core.exceptions``; each model
37
class contains a subclassed version that can be used to identify the
38
specific object type that has returned multiple objects.
40
See :meth:`~django.db.models.QuerySet.get()` for further information.
45
The ``SuspiciousOperation`` exception is raised when a user has performed
46
an operation that should be considered suspicious from a security perspective,
47
such as tampering with a session cookie.
52
The ``PermissionDenied`` exception is raised when a user does not have
53
permission to perform the action requested.
58
The ``ViewDoesNotExist`` exception is raised by
59
``django.core.urlresolvers`` when a requested view does not exist.
64
The ``MiddlewareNotUsed`` exception is raised when a middleware is not
65
used in the server configuration.
70
The ``ImproperlyConfigured`` exception is raised when Django is
71
somehow improperly configured -- for example, if a value in ``settings.py``
72
is incorrect or unparseable.
77
The ``FieldError`` exception is raised when there is a problem with a
78
model field. This can happen for several reasons:
80
- A field in a model clashes with a field of the same name from an
82
- An infinite loop is caused by ordering
83
- A keyword cannot be parsed from the filter parameters
84
- If a field cannot be determined from a keyword in the query
86
- If a join is not permitted on the specified field
87
- If a field name is invalid
88
- If a query contains invalid order_by arguments
93
Django wraps the standard database exceptions ``DatabaseError`` and
94
``IntegrityError`` so that your Django code has a guaranteed common
95
implementation of these classes. These database exceptions are
96
provided in ``django.db``.
98
The Django wrappers for database exceptions behave exactly the same as
99
the underlying database exceptions. See `PEP 249 - Python Database API
100
Specification v2.0`_ for further information.
102
.. _`PEP 249 - Python Database API Specification v2.0`: http://www.python.org/dev/peps/pep-0249/
107
Django raises built-in Python exceptions when appropriate as well. See
108
the Python `documentation`_ for further information on the built-in
111
.. _`documentation`: http://docs.python.org/lib/module-exceptions.html