Python ';WSGIRequest&x27;对象没有属性';是经过认证的';
我正在我的Python ';WSGIRequest&x27;对象没有属性';是经过认证的';,python,django-2.1,Python,Django 2.1,我正在我的视图.py中检查用户是否经过身份验证。然而,Django不断抛出异常WSGIRequest对象没有属性“is\u authenticated”。我通读了stackoverflow和github关于这个问题的一些类似问题,每个人都指向移动中间件。我已经尝试了几乎所有的方法来重组我的中间件,就像其他回答中提到的一样,但我没有能够解决这个问题。我甚至阅读了一些文档,但没有从中收集到太多信息 views.py @staticmethod def cmshome(request): if
视图.py中检查用户是否经过身份验证。然而,Django不断抛出异常WSGIRequest对象没有属性“is\u authenticated”
。我通读了stackoverflow和github关于这个问题的一些类似问题,每个人都指向移动中间件。我已经尝试了几乎所有的方法来重组我的中间件,就像其他回答中提到的一样,但我没有能够解决这个问题。我甚至阅读了一些文档,但没有从中收集到太多信息
views.py
@staticmethod
def cmshome(request):
if request.is_authenticated:
return redirect('/cms/')
username = request.session['user']
profile_object = Profile.objects.all().filter(user__username=username)
return render(request, 'cms/cmshome.html', {'profile_content': profile_object})
中间件
MIDDLEWARE_CLASSES = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
也许你想写:
if request.user.is_authenticated:
return redirect('/cms/')
也许你想写:
if request.user.is_authenticated:
return redirect('/cms/')