exceptions.txt 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. =================
  2. Django Exceptions
  3. =================
  4. Django raises some Django specific exceptions as well as many standard
  5. Python exceptions.
  6. Django-specific Exceptions
  7. ==========================
  8. .. module:: django.core.exceptions
  9. :synopsis: Django specific exceptions
  10. ObjectDoesNotExist and DoesNotExist
  11. -----------------------------------
  12. .. exception:: DoesNotExist
  13. .. exception:: ObjectDoesNotExist
  14. The :exc:`DoesNotExist` exception is raised when an object is not found
  15. for the given parameters of a query.
  16. :exc:`ObjectDoesNotExist` is defined in :mod:`django.core.exceptions`.
  17. :exc:`DoesNotExist` is a subclass of the base :exc:`ObjectDoesNotExist`
  18. exception that is provided on every model class as a way of
  19. identifying the specific type of object that could not be found.
  20. See :meth:`~django.db.models.query.QuerySet.get()` for further information
  21. on :exc:`ObjectDoesNotExist` and :exc:`DoesNotExist`.
  22. MultipleObjectsReturned
  23. -----------------------
  24. .. exception:: MultipleObjectsReturned
  25. The :exc:`MultipleObjectsReturned` exception is raised by a query if only
  26. one object is expected, but multiple objects are returned. A base version
  27. of this exception is provided in :mod:`django.core.exceptions`; each model
  28. class contains a subclassed version that can be used to identify the
  29. specific object type that has returned multiple objects.
  30. See :meth:`~django.db.models.query.QuerySet.get()` for further information.
  31. SuspiciousOperation
  32. -------------------
  33. .. exception:: SuspiciousOperation
  34. The :exc:`SuspiciousOperation` exception is raised when a user has
  35. performed an operation that should be considered suspicious from a security
  36. perspective, such as tampering with a session cookie. Subclasses of
  37. SuspiciousOperation include:
  38. * DisallowedHost
  39. * DisallowedModelAdminLookup
  40. * DisallowedRedirect
  41. * InvalidSessionKey
  42. * SuspiciousFileOperation
  43. * SuspiciousMultipartForm
  44. * SuspiciousSession
  45. * WizardViewCookieModified
  46. If a ``SuspiciousOperation`` exception reaches the WSGI handler level it is
  47. logged at the ``Error`` level and results in
  48. a :class:`~django.http.HttpResponseBadRequest`. See the :doc:`logging
  49. documentation </topics/logging/>` for more information.
  50. PermissionDenied
  51. ----------------
  52. .. exception:: PermissionDenied
  53. The :exc:`PermissionDenied` exception is raised when a user does not have
  54. permission to perform the action requested.
  55. ViewDoesNotExist
  56. ----------------
  57. .. exception:: ViewDoesNotExist
  58. The :exc:`ViewDoesNotExist` exception is raised by
  59. :mod:`django.core.urlresolvers` when a requested view does not exist.
  60. MiddlewareNotUsed
  61. -----------------
  62. .. exception:: MiddlewareNotUsed
  63. The :exc:`MiddlewareNotUsed` exception is raised when a middleware is not
  64. used in the server configuration.
  65. ImproperlyConfigured
  66. --------------------
  67. .. exception:: ImproperlyConfigured
  68. The :exc:`ImproperlyConfigured` exception is raised when Django is
  69. somehow improperly configured -- for example, if a value in ``settings.py``
  70. is incorrect or unparseable.
  71. FieldError
  72. ----------
  73. .. exception:: FieldError
  74. The :exc:`FieldError` exception is raised when there is a problem with a
  75. model field. This can happen for several reasons:
  76. - A field in a model clashes with a field of the same name from an
  77. abstract base class
  78. - An infinite loop is caused by ordering
  79. - A keyword cannot be parsed from the filter parameters
  80. - A field cannot be determined from a keyword in the query
  81. parameters
  82. - A join is not permitted on the specified field
  83. - A field name is invalid
  84. - A query contains invalid order_by arguments
  85. ValidationError
  86. ---------------
  87. .. exception:: ValidationError
  88. The :exc:`ValidationError` exception is raised when data fails form or
  89. model field validation. For more information about validation, see
  90. :doc:`Form and Field Validation </ref/forms/validation>`,
  91. :ref:`Model Field Validation <validating-objects>` and the
  92. :doc:`Validator Reference </ref/validators>`.
  93. .. currentmodule:: django.core.urlresolvers
  94. NoReverseMatch
  95. --------------
  96. .. exception:: NoReverseMatch
  97. The :exc:`NoReverseMatch` exception is raised by
  98. :mod:`django.core.urlresolvers` when a matching URL in your URLconf
  99. cannot be identified based on the parameters supplied.
  100. .. currentmodule:: django.db
  101. Database Exceptions
  102. ===================
  103. Django wraps the standard database exceptions so that your Django code has a
  104. guaranteed common implementation of these classes. These database exceptions
  105. are provided in :mod:`django.db`.
  106. .. exception:: Error
  107. .. exception:: InterfaceError
  108. .. exception:: DatabaseError
  109. .. exception:: DataError
  110. .. exception:: OperationalError
  111. .. exception:: IntegrityError
  112. .. exception:: InternalError
  113. .. exception:: ProgrammingError
  114. .. exception:: NotSupportedError
  115. The Django wrappers for database exceptions behave exactly the same as
  116. the underlying database exceptions. See :pep:`249`, the Python Database API
  117. Specification v2.0, for further information.
  118. .. versionchanged:: 1.6
  119. Previous version of Django only wrapped ``DatabaseError`` and
  120. ``IntegrityError``.
  121. .. exception:: models.ProtectedError
  122. Raised to prevent deletion of referenced objects when using
  123. :attr:`django.db.models.PROTECT`. Subclass of :exc:`IntegrityError`.
  124. .. currentmodule:: django.http
  125. Http Exceptions
  126. ===============
  127. .. exception:: UnreadablePostError
  128. The :exc:`UnreadablePostError` is raised when a user cancels an upload.
  129. It is available from :mod:`django.http`.
  130. .. currentmodule:: django.db.transaction
  131. Transaction Exceptions
  132. ======================
  133. .. exception:: TransactionManagementError
  134. The :exc:`TransactionManagementError` is raised for any and all problems
  135. related to database transactions. It is available from
  136. :mod:`django.db.transaction`.
  137. Python Exceptions
  138. =================
  139. Django raises built-in Python exceptions when appropriate as well. See the
  140. Python documentation for further information on the
  141. built-in :mod:`exceptions`.