exceptions.txt 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. .. _ref-exceptions:
  2. =================
  3. Django Exceptions
  4. =================
  5. Django raises some Django specific exceptions as well as many standard
  6. Python exceptions.
  7. Django-specific Exceptions
  8. ==========================
  9. .. module:: django.core.exceptions
  10. :synopsis: Django specific exceptions
  11. ObjectDoesNotExist and DoesNotExist
  12. -----------------------------------
  13. The ``DoesNotExist`` exception is raised when an object is not found
  14. for the given parameters of a query.
  15. ``ObjectDoesNotExist`` is defined in ``django.core.exceptions``.
  16. ``DoesNotExist`` is a subclass of the base ``ObjectDoesNotExist``
  17. exception that is provided on every model class as a way of
  18. identifying the specific type of object that could not be found.
  19. See :meth:`~django.db.models.QuerySet.get()` for further information
  20. on ``ObjectDoesNotExist`` and ``DoesNotExist``.
  21. MultipleObjectsReturned
  22. -----------------------
  23. The ``MultipleObjectsReturned`` exception is raised by a query if only
  24. one object is expected, but multiple objects are returned. A base version
  25. of this exception is provided in ``django.core.exceptions``; each model
  26. class contains a subclassed version that can be used to identify the
  27. specific object type that has returned multiple objects.
  28. See :meth:`~django.db.models.QuerySet.get()` for further information.
  29. SuspiciousOperation
  30. -------------------
  31. The ``SuspiciousOperation`` exception is raised when a user has performed
  32. an operation that should be considered suspicious from a security perspective,
  33. such as tampering with a session cookie.
  34. PermissionDenied
  35. ----------------
  36. The ``PermissionDenied`` exception is raised when a user does not have
  37. permission to perform the action requested.
  38. ViewDoesNotExist
  39. ----------------
  40. The ``ViewDoesNotExist`` exception is raised by
  41. ``django.core.urlresolvers`` when a requested view does not exist.
  42. MiddlewareNotUsed
  43. -----------------
  44. The ``MiddlewareNotUsed`` exception is raised when a middleware is not
  45. used in the server configuration.
  46. ImproperlyConfigured
  47. --------------------
  48. The ``ImproperlyConfigured`` exception is raised when Django is
  49. somehow improperly configured -- for example, if a value in ``settings.py``
  50. is incorrect or unparseable.
  51. FieldError
  52. ----------
  53. The ``FieldError`` exception is raised when there is a problem with a
  54. model field. This can happen for several reasons:
  55. - A field in a model clashes with a field of the same name from an
  56. abstract base class
  57. - An infinite loop is caused by ordering
  58. - A keyword cannot be parsed from the filter parameters
  59. - If a field cannot be determined from a keyword in the query
  60. parameters
  61. - If a join is not permitted on the specified field
  62. - If a field name is invalid
  63. - If a query contains invalid order_by arguments
  64. Database Exceptions
  65. ===================
  66. Django wraps the standard database exceptions ``DatabaseError`` and
  67. ``IntegrityError`` so that your Django code has a guaranteed common
  68. implementation of these classes. These database exceptions are
  69. provided in ``django.db``.
  70. The Django wrappers for database exceptions behave exactly the same as
  71. the underlying database exceptions. See `PEP 249 - Python Database API
  72. Specification v2.0`_ for further information.
  73. .. _`PEP 249 - Python Database API Specification v2.0`: http://www.python.org/dev/peps/pep-0249/
  74. Python Exceptions
  75. =================
  76. Django raises built-in Python exceptions when appropriate as well. See
  77. the Python `documentation`_ for further information on the built-in
  78. exceptions.
  79. .. _`documentation`: http://docs.python.org/lib/module-exceptions.html