Django の例外Link to this heading

Django は普通の Python の例外の他に、いくつか独自の例外も起こします。

Django Core 例外Link to this heading

Django core 例外クラスは django.core.exceptions で定義されています。

AppRegistryNotReadyLink to this heading

exception AppRegistryNotReadyLink to this definition

This exception is raised when attempting to use models before the app loading process, which initializes the ORM, is complete.

ObjectDoesNotExistLink to this heading

exception ObjectDoesNotExistLink to this definition

The base class for DoesNotExist exceptions; a try/except for ObjectDoesNotExist will catch DoesNotExist exceptions for all models.

See get() for further information on ObjectDoesNotExist and DoesNotExist.

EmptyResultSetLink to this heading

exception EmptyResultSetLink to this definition

EmptyResultSet may be raised during query generation if a query won't return any results. Most Django projects won't encounter this exception, but it might be useful for implementing custom lookups and expressions.

FieldDoesNotExistLink to this heading

exception FieldDoesNotExistLink to this definition

The FieldDoesNotExist exception is raised by a model's _meta.get_field() method when the requested field does not exist on the model or on the model's parents.

MultipleObjectsReturnedLink to this heading

exception MultipleObjectsReturnedLink to this definition

The MultipleObjectsReturned exception is raised by a query if only one object is expected, but multiple objects are returned. A base version of this exception is provided in django.core.exceptions; each model class contains a subclassed version that can be used to identify the specific object type that has returned multiple objects.

詳しくは get() を見てください。

SuspiciousOperationLink to this heading

exception SuspiciousOperationLink to this definition

The SuspiciousOperation exception is raised when a user has performed an operation that should be considered suspicious from a security perspective, such as tampering with a session cookie. Subclasses of SuspiciousOperation include:

  • DisallowedHost

  • DisallowedModelAdminLookup

  • DisallowedModelAdminToField

  • DisallowedRedirect

  • InvalidSessionKey

  • RequestDataTooBig

  • SuspiciousFileOperation

  • SuspiciousMultipartForm

  • SuspiciousSession

  • TooManyFieldsSent

SuspiciousOperation 例外が WSGI ハンドラーのレベルに到達すると、Error レベルがログに記録され、HttpResponseBadRequest が返されます。詳しくは logging documentation を参照してください。

PermissionDeniedLink to this heading

exception PermissionDeniedLink to this definition

PermissionDenied 例外は、ユーザーにリクエストされたアクションを実行する権限がない場合に発生します。

ViewDoesNotExistLink to this heading

exception ViewDoesNotExistLink to this definition

ViewDoesNotExist 例外は、リクエストされたビューが存在しないい場合に、django.urls によって発生します。

MiddlewareNotUsedLink to this heading

exception MiddlewareNotUsedLink to this definition

MiddlewareNotUsed 例外は、サーバーの設定の中でミドルウェアが使用されなかった時に発生します。

ImproperlyConfiguredLink to this heading

exception ImproperlyConfiguredLink to this definition

ImproperlyConfigured 例外は、Django が何らかの点で不適切に設定されている場合に発生します。たとえば、settings.py に含まれる値が不正であったり、パースできないような場合が考えられます。

FieldErrorLink to this heading

exception FieldErrorLink to this definition

FieldError 例外は、モデルのフィールドに問題がある時に発生します。発生理由としては、次のようないくつかの理由が考えられます。

  • A field in a model clashes with a field of the same name from an abstract base class

  • An infinite loop is caused by ordering

  • A keyword cannot be parsed from the filter parameters

  • A field cannot be determined from a keyword in the query parameters

  • A join is not permitted on the specified field

  • A field name is invalid

  • A query contains invalid order_by arguments

ValidationErrorLink to this heading

exception ValidationErrorLink to this definition

ValidationError 例外は、データがフォームまたはモデルのフィールド検証に失敗すると発生します。検証 (validation) のより詳しい情報については、Form and Field ValidationModel Field ValidationValidator Reference を参照してください。

NON_FIELD_ERRORSLink to this heading

NON_FIELD_ERRORSLink to this definition

ValidationErrors that don't belong to a particular field in a form or model are classified as NON_FIELD_ERRORS. This constant is used as a key in dictionaries that otherwise map fields to their respective list of errors.

URL Resolver の例外Link to this heading

URL Resolver の例外は django.urls で定義されています。

Resolver404Link to this heading

exception Resolver404Link to this definition

The Resolver404 exception is raised by resolve() if the path passed to resolve() doesn't map to a view. It's a subclass of django.http.Http404.

NoReverseMatchLink to this heading

exception NoReverseMatchLink to this definition

The NoReverseMatch exception is raised by django.urls when a matching URL in your URLconf cannot be identified based on the parameters supplied.

データベースの例外Link to this heading

データベースの例外は django.db からインポートできます。

Django wraps the standard database exceptions so that your Django code has a guaranteed common implementation of these classes.

exception ErrorLink to this definition
exception InterfaceErrorLink to this definition
exception DatabaseErrorLink to this definition
exception DataErrorLink to this definition
exception OperationalErrorLink to this definition
exception IntegrityErrorLink to this definition
exception InternalErrorLink to this definition
exception ProgrammingErrorLink to this definition
exception NotSupportedErrorLink to this definition

The Django wrappers for database exceptions behave exactly the same as the underlying database exceptions. See PEP 249, the Python Database API Specification v2.0, for further information.

As per PEP 3134, a __cause__ attribute is set with the original (underlying) database exception, allowing access to any additional information provided.

exception models.ProtectedErrorLink to this definition

Raised to prevent deletion of referenced objects when using django.db.models.PROTECT. models.ProtectedError is a subclass of IntegrityError.

Http の例外Link to this heading

Http の例外は django.http からインポートすることができます。

UnreadablePostErrorLink to this heading

exception UnreadablePostErrorLink to this definition

UnreadablePostError は、ユーザーがアップロードをキャンセルすると発生します。

トランザクションの例外Link to this heading

トランザクションの例外は django.db.transaction で定義されています。

TransactionManagementErrorLink to this heading

exception TransactionManagementErrorLink to this definition

TransactionManagementError が発生するのは、データベースのトランザクションに関するあらゆる問題に対してです。

テストフレームワークの例外Link to this heading

django.test パッケージが提供する例外です。

RedirectCycleErrorLink to this heading

exception client.RedirectCycleErrorLink to this definition

RedirectCycleError は、テストクライアントがループまたは過度に長いリダイレクトチェーンを検出した時に発生します。

Python の例外Link to this heading

Django は、十分適切な場合にはビルトインの Python の例外を起こします。詳しい情報については、Python のドキュメント Built-in Exceptions を読んでください。