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