exceptions.txt 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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.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.QuerySet.get()` for further information.
  31. SuspiciousOperation
  32. -------------------
  33. .. exception:: SuspiciousOperation
  34. The :exc:`SuspiciousOperation` exception is raised when a user has performed
  35. an operation that should be considered suspicious from a security perspective,
  36. such as tampering with a session cookie.
  37. PermissionDenied
  38. ----------------
  39. .. exception:: PermissionDenied
  40. The :exc:`PermissionDenied` exception is raised when a user does not have
  41. permission to perform the action requested.
  42. ViewDoesNotExist
  43. ----------------
  44. .. exception:: ViewDoesNotExist
  45. The :exc:`ViewDoesNotExist` exception is raised by
  46. :mod:`django.core.urlresolvers` when a requested view does not exist.
  47. MiddlewareNotUsed
  48. -----------------
  49. .. exception:: MiddlewareNotUsed
  50. The :exc:`MiddlewareNotUsed` exception is raised when a middleware is not
  51. used in the server configuration.
  52. ImproperlyConfigured
  53. --------------------
  54. .. exception:: ImproperlyConfigured
  55. The :exc:`ImproperlyConfigured` exception is raised when Django is
  56. somehow improperly configured -- for example, if a value in ``settings.py``
  57. is incorrect or unparseable.
  58. FieldError
  59. ----------
  60. .. exception:: FieldError
  61. The :exc:`FieldError` exception is raised when there is a problem with a
  62. model field. This can happen for several reasons:
  63. - A field in a model clashes with a field of the same name from an
  64. abstract base class
  65. - An infinite loop is caused by ordering
  66. - A keyword cannot be parsed from the filter parameters
  67. - A field cannot be determined from a keyword in the query
  68. parameters
  69. - A join is not permitted on the specified field
  70. - A field name is invalid
  71. - A query contains invalid order_by arguments
  72. ValidationError
  73. ---------------
  74. .. exception:: ValidationError
  75. The :exc:`ValidationError` exception is raised when data fails form or
  76. model field validation. For more information about validation, see
  77. :doc:`Form and Field Validation </ref/forms/validation>`,
  78. :ref:`Model Field Validation <validating-objects>` and the
  79. :doc:`Validator Reference </ref/validators>`.
  80. .. currentmodule:: django.core.urlresolvers
  81. NoReverseMatch
  82. --------------
  83. .. exception:: NoReverseMatch
  84. The :exc:`NoReverseMatch` exception is raised by
  85. :mod:`django.core.urlresolvers` when a matching URL in your URLconf
  86. cannot be identified based on the parameters supplied.
  87. .. currentmodule:: django.db
  88. Database Exceptions
  89. ===================
  90. Django wraps the standard database exceptions :exc:`DatabaseError` and
  91. :exc:`IntegrityError` so that your Django code has a guaranteed common
  92. implementation of these classes. These database exceptions are
  93. provided in :mod:`django.db`.
  94. .. exception:: DatabaseError
  95. .. exception:: IntegrityError
  96. The Django wrappers for database exceptions behave exactly the same as
  97. the underlying database exceptions. See `PEP 249 - Python Database API
  98. Specification v2.0`_ for further information.
  99. .. _`PEP 249 - Python Database API Specification v2.0`: http://www.python.org/dev/peps/pep-0249/
  100. Python Exceptions
  101. =================
  102. Django raises built-in Python exceptions when appropriate as well. See
  103. the Python `documentation`_ for further information on the built-in
  104. exceptions.
  105. .. _`documentation`: http://docs.python.org/lib/module-exceptions.html