| 1 | ================= |
| 2 | Django Exceptions |
| 3 | ================= |
| 4 | |
| 5 | This document describes the exceptions raised by Django. |
| 6 | |
| 7 | Django raises some Django specific exceptions as well as many standard Python exceptions. |
| 8 | |
| 9 | Django Specific Exceptions |
| 10 | ========================== |
| 11 | |
| 12 | Most of the Django specific exceptions are in the ``django.core.exceptions`` module. For example, |
| 13 | ``django.core.exceptions.ViewDoesNotExist``. |
| 14 | |
| 15 | ObjectDoesNotExist and DoesNotExist |
| 16 | ----------------------------------- |
| 17 | The ``DoesNotExist`` exception is raised when an object is not found for the given parameters of a |
| 18 | query. The ``DoesNotExist`` exception is not in ``django.core.exceptions``. Instead, it is an |
| 19 | attribute of the model class and inherits from ``ObjectDoesNotExist`` which is in |
| 20 | ``django.core.exceptions``. See `get`_ for further information on ``ObjectDoesNotExist`` and |
| 21 | ``DoesNotExist``. |
| 22 | |
| 23 | .. _`get`: ../db-api/#get-kwargs |
| 24 | |
| 25 | MultipleObjectsReturned |
| 26 | ----------------------- |
| 27 | The ``MultipleObjectsReturned`` exception is raised by a query if only one object is expected, but |
| 28 | multiple objects are returned. See `get`_ for further information. The ``MultipleObjectsReturned`` |
| 29 | exception is an attribute of a model class and it is in ``django.core.exceptions``. |
| 30 | |
| 31 | .. _`get`: ../db-api/#get-kwargs |
| 32 | |
| 33 | SuspiciousOperation |
| 34 | ------------------- |
| 35 | The ``SuspiciousOperation`` exception is raised when a user did something suspicious. |
| 36 | |
| 37 | PermissionDenied |
| 38 | ---------------- |
| 39 | The ``PermissionDenied`` exception is raised when a user does not have permission to perform the action |
| 40 | attempted. |
| 41 | |
| 42 | ViewDoesNotExist |
| 43 | ---------------- |
| 44 | The ``ViewDoesNotExist`` exception is raised by ``django.core.urlresolvers`` when a requested view does |
| 45 | not exist. |
| 46 | |
| 47 | MiddlewareNotUsed |
| 48 | ----------------- |
| 49 | The ``MiddlewareNotUsed`` exception is raised when a middleware is not used in the server configuration. |
| 50 | |
| 51 | ImproperlyConfigured |
| 52 | -------------------- |
| 53 | The ``ImproperlyConfigured`` exception is raised when Django is somehow improperly configured. |
| 54 | |
| 55 | FieldError |
| 56 | ---------- |
| 57 | The ``FieldError`` exception is raised when there is a problem with a model field. This can happen for |
| 58 | several reasons, some of which are: |
| 59 | |
| 60 | - A field in a model clashes with a field of the same name from an abstract base class |
| 61 | - An infinite loop is caused by ordering |
| 62 | - A keyword cannot be parsed from the filter parameters |
| 63 | - If a field cannot be determined from a keyword in the query parameters |
| 64 | - If a join is not permitted on the specified field |
| 65 | - If a field name is invalid |
| 66 | - If a query contains invalid order_by arguments |
| 67 | |
| 68 | Database Exceptions |
| 69 | =================== |
| 70 | Django raises or propagates standard database exceptions, such as DatabaseError and IntegrityError, |
| 71 | when appropriate for operations on model objects. See |
| 72 | `PEP 249 - Python Database API Specification v2.0`_ for further information about database exceptions. |
| 73 | |
| 74 | .. _`PEP 249 - Python Database API Specification v2.0`: http://www.python.org/dev/peps/pep-0249/ |
| 75 | |
| 76 | Python Exceptions |
| 77 | ================= |
| 78 | Django raises built-in Python exceptions when appropriate as well. See the Python `documentation`_ for |
| 79 | further information on the built-in exceptions. |
| 80 | |
| 81 | .. _`documentation`: http://docs.python.org/lib/module-exceptions.html |
| 82 | |