Django2 login package error 'WSGIRequest' object has no attribute' session'

call the login method that comes with django when logging in: from django.contrib.auth import login, authenticate

user = authenticate (username=username, password=password)
login (request, user)
threw the error of "WSGIRequest" object has no attribute" session" in this sentence. I checked on the Internet and said that the name of middle in settings is wrong, but I checked that my name is right: MIDDLEWARE_CLASSES, please point out that the version I use is django2.1.1. Thank you

.

my classes goes like this:
MIDDLEWARE_CLASSES = (

)
"django.contrib.sessions.middleware.SessionMiddleware",
"django.middleware.common.CommonMiddleware",
"django.middleware.csrf.CsrfViewMiddleware",
"django.contrib.auth.middleware.AuthenticationMiddleware",
"django.contrib.auth.middleware.SessionAuthenticationMiddleware",
"django.contrib.messages.middleware.MessageMiddleware",
"django.middleware.clickjacking.XFrameOptionsMiddleware",
"django.middleware.security.SecurityMiddleware",

)

Jul.23,2021

when calling login (request, user), it accesses the request.session property,
and request.session initializes
in django.contrib.sessions.middleware.SessionMiddleware middleware, so the problem is that the middleware does not call the session attribute
because the django2.0 middleware configuration variable name is MIDDLEWARE is no longer MIDDLEWARE_CLASSES
, so the correct configuration is:

MIDDLEWARE = (
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'django.middleware.security.SecurityMiddleware',
)
Menu