[Fixed]-'WSGIRequest' object has no attribute 'session'

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).

πŸ‘€sunprophit

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/

πŸ‘€mateuszb

Leave a comment