19π
The problem was in middlewares order.
CommonMiddleware returns HttpResponsePermanentRedirect in cases when to request url have been added βwwwβ or trailing β/β (APPEND_SLASH and PREPEND_WWW in settings). In such case django stops looking through middleware list for process_request methods and begins to run process_response methods.
Itβs bad there is no information about such behavior for standard django middlewares (i.e. middleware could return in some cases HttpResponse object).
5π
If you came here because you updated to Django 2.0 and get this error, you might want to know that name MIDDLEWARE_CLASSES
was replaced with MIDDLEWARE
.
More here https://stackoverflow.com/a/47650447/1218179 and here https://docs.djangoproject.com/en/2.0/topics/http/middleware/