1
0
mirror of https://github.com/django/django.git synced 2025-10-25 06:36:07 +00:00

Refs #32508 -- Raised ImproperlyConfigured instead of using "assert" in middlewares.

This commit is contained in:
Hasan Ramezani
2021-03-10 14:08:37 +01:00
committed by Mariusz Felisiak
parent dc86a25a67
commit a2d5ea626e
4 changed files with 19 additions and 13 deletions

View File

@@ -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()