django
Django Exception Types
Exception and error classes raised by the Django web framework. Covers ORM failures, HTTP shortcut exceptions, configuration errors, template rendering errors, and URL resolution failures.
18 codes
· All codes 18 codes
- AppRegistryNotReady AppRegistryNotReady Raised when application code tries to access the app registry (e.g. import models) before Django has finished loading all apps. Commonly triggered by top-level model imports in AppConfig.ready() or module-level ORM calls executed at import time.
- DisallowedHost DisallowedHost Raised (as a SuspiciousOperation subclass) when the HTTP Host header does not match any entry in settings.ALLOWED_HOSTS. Results in a 400 Bad Request. Add the domain or IP address to ALLOWED_HOSTS, or set ALLOWED_HOSTS = ['*'] during local development.
- DoesNotExist DoesNotExist Raised by Model.objects.get() when no record matches the query filter. Each model class has its own DoesNotExist subclass (e.g. User.DoesNotExist). Use get_object_or_404() in views, or catch explicitly to return a fallback response.
- FieldDoesNotExist FieldDoesNotExist Raised by Model._meta.get_field() when the requested field name does not exist on the model. Also seen in the Django admin when fields or list_display references a non-existent field name.
- Http404 Http404 Raised by a view to return an HTTP 404 Not Found response. The convenience function get_object_or_404() raises this automatically when a queryset returns no results. Handled by the 404.html template or a custom handler404 view.
- ImproperlyConfigured ImproperlyConfigured Raised when Django detects an invalid or incomplete configuration, such as a missing required setting, an unrecognised database engine, or a misconfigured installed app. Resolving this error typically requires fixing settings.py.
- IntegrityError IntegrityError Raised when a database integrity constraint is violated through the Django ORM — for example, inserting a duplicate value in a unique column, violating a NOT NULL constraint, or breaking a foreign key reference. Subclass of django.db.DatabaseError.
- MiddlewareNotUsed MiddlewareNotUsed Raised from a middleware class's __init__ to signal that Django should remove it from the middleware stack for this request cycle. Useful for disabling middleware conditionally based on settings or request properties.
- MultipleObjectsReturned MultipleObjectsReturned Raised by Model.objects.get() when more than one record matches the given filter. Use filter().first() if multiple results are acceptable, or add further constraints to make the lookup unique.
- NoReverseMatch NoReverseMatch Raised by reverse() or the {% url %} template tag when no URL pattern in the URLconf matches the given view name and arguments. Check the url name, any URL namespace prefix, and that all required positional or keyword arguments are supplied.
- ObjectDoesNotExist ObjectDoesNotExist Base class for all model-specific DoesNotExist exceptions. Catching ObjectDoesNotExist handles missing-record errors for any model type in a single except clause, useful in generic views and shared utility functions.
- OperationalError OperationalError Raised for database problems that are not under the programmer's control: lost connections, table lock timeouts, and similar operational failures. Django wraps the underlying database driver's error as django.db.OperationalError.
- PermissionDenied PermissionDenied Raised by a view or middleware to return an HTTP 403 Forbidden response. Complement with @login_required and @permission_required decorators, or raise PermissionDenied() explicitly when the current user lacks the required access.
- RequestDataTooBig RequestDataTooBig Raised when a POST body or file upload exceeds DATA_UPLOAD_MAX_MEMORY_SIZE or FILE_UPLOAD_MAX_MEMORY_SIZE (default 2.5 MB). Increase these settings for large uploads, or process data as a stream rather than reading the full body into memory.
- SuspiciousOperation SuspiciousOperation Raised when Django detects potentially malicious input such as a tampered session cookie, a CSRF token mismatch, or invalid multipart data. Subclasses include DisallowedHost and SuspiciousFileOperation. Results in a 400 Bad Request by default.
- TemplateDoesNotExist TemplateDoesNotExist Raised by the template engine when no configured loader can locate the named template file. Check TEMPLATES[...]['DIRS'] in settings, ensure the app's templates/ subdirectory is correctly structured, and verify that the app is listed in INSTALLED_APPS.
- TemplateSyntaxError TemplateSyntaxError Raised when the Django template engine encounters invalid syntax in a template file, such as an unclosed block tag, an unknown filter name, or a malformed variable expression.
- ValidationError ValidationError Raised when a form field, model field, or serializer fails validation. The exception carries a messages list describing each failure. In Django REST Framework it is also raised by serializer validators and produces a 400 Bad Request response.