gpt4 book ai didi

python - Django : 'WSGIRequest' object has no attribute 'user' ? - AuthenticationMiddleware & SessionAuthenticationMiddleware 顺序

转载 作者:太空宇宙 更新时间:2023-11-03 13:36:32 26 4
gpt4 key购买 nike

尝试访问 django 管理面板时出现以下错误。

Environment:

Request Method: GET
Request URL: http://localhost:8000/admin/

Django Version: 1.9.8
Python Version: 2.7.10
Installed Applications:
['django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'bookapp']
Installed Middleware:
['django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware']

Traceback:

File "/Library/Python/2.7/site-packages/django/core/handlers/base.py" in get_response
149. response = self.process_exception_by_middleware(e, request)

File "/Library/Python/2.7/site-packages/django/core/handlers/base.py" in get_response
147. response = wrapped_callback(request, *callback_args, **callback_kwargs)

File "/Library/Python/2.7/site-packages/django/contrib/admin/sites.py" in wrapper
265. return self.admin_view(view, cacheable)(*args, **kwargs)

File "/Library/Python/2.7/site-packages/django/utils/decorators.py" in _wrapped_view
149. response = view_func(request, *args, **kwargs)

File "/Library/Python/2.7/site-packages/django/views/decorators/cache.py" in _wrapped_view_func
57. response = view_func(request, *args, **kwargs)

File "/Library/Python/2.7/site-packages/django/contrib/admin/sites.py" in inner
233. if not self.has_permission(request):

File "/Library/Python/2.7/site-packages/django/contrib/admin/sites.py" in has_permission
173. return request.user.is_active and request.user.is_staff

Exception Type: AttributeError at /admin/
Exception Value: 'WSGIRequest' object has no attribute 'user'

这是我在 settings.py 中的中间件设置

MIDDLEWARE_CLASSES = [
'django.middleware.security.SecurityMiddleware',
'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',
]

我还尝试过清除缓存,例如清除迁移和删除数据库。但这对我不起作用。

谁能知道这里的问题是什么?

最佳答案

将名称 MIDDLEWARE 更改为 MIDDLEWARE_CLASSES

关于python - Django : 'WSGIRequest' object has no attribute 'user' ? - AuthenticationMiddleware & SessionAuthenticationMiddleware 顺序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38826118/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com