diff options
| author | Hasan Ramezani <hasan.r67@gmail.com> | 2021-03-10 14:08:37 +0100 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2021-03-11 08:34:28 +0100 |
| commit | a2d5ea626ec6aa4eab6b018c4bce58cb27e20676 (patch) | |
| tree | 0a76e91b333d863300d771c8a4486a3e753023d6 /django/contrib/admindocs | |
| parent | dc86a25a677d05703e0bb021b178e44412cea7e9 (diff) | |
Refs #32508 -- Raised ImproperlyConfigured instead of using "assert" in middlewares.
Diffstat (limited to 'django/contrib/admindocs')
| -rw-r--r-- | django/contrib/admindocs/middleware.py | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/django/contrib/admindocs/middleware.py b/django/contrib/admindocs/middleware.py index 4779db8366..cf8879d75a 100644 --- a/django/contrib/admindocs/middleware.py +++ b/django/contrib/admindocs/middleware.py @@ -1,4 +1,5 @@ from django.conf import settings +from django.core.exceptions import ImproperlyConfigured from django.http import HttpResponse from django.utils.deprecation import MiddlewareMixin @@ -16,11 +17,12 @@ class XViewMiddleware(MiddlewareMixin): header indicating the view function. This is used to lookup the view function for an arbitrary page. """ - assert hasattr(request, 'user'), ( - "The XView middleware requires authentication middleware to be " - "installed. Edit your MIDDLEWARE setting to insert " - "'django.contrib.auth.middleware.AuthenticationMiddleware'." - ) + if not hasattr(request, 'user'): + raise ImproperlyConfigured( + "The XView middleware requires authentication middleware to " + "be installed. Edit your MIDDLEWARE setting to insert " + "'django.contrib.auth.middleware.AuthenticationMiddleware'." + ) if request.method == 'HEAD' and (request.META.get('REMOTE_ADDR') in settings.INTERNAL_IPS or (request.user.is_active and request.user.is_staff)): response = HttpResponse() |
