报错问题之:AttributeError: 'WSGIRequest' object has no attribute 'user'

Traceback (most recent call last):
  File "D:\pyvenv\educate\lib\site-packages\django\core\handlers\base.py", line 149, in get_response
    response = self.process_exception_by_middleware(e, request)
  File "D:\pyvenv\educate\lib\site-packages\django\core\handlers\base.py", line 147, in get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "D:\projects\eduweb\extra_apps\xadmin\sites.py", line 300, in wrapper
    return self.admin_view(view, cacheable)(*args, **kwargs)
  File "D:\pyvenv\educate\lib\site-packages\django\views\decorators\cache.py", line 57, in _wrapped_view_func
    response = view_func(request, *args, **kwargs)
  File "D:\projects\eduweb\extra_apps\xadmin\sites.py", line 206, in inner
    if not self.has_permission(request) and getattr(view, 'need_site_permission', True):
  File "D:\projects\eduweb\extra_apps\xadmin\sites.py", line 161, in has_permission
    return request.user.is_active and request.user.is_staff
AttributeError: 'WSGIRequest' object has no attribute 'user'

百度了下,说是MIDDLEWARE配置的有问题,不同版本之间的django中间键是不一样的:

Django 1.9 和以前的版本:
MIDDLEWARE_CLASSES = (
    'zqxt.middleware.BlockedIpMiddleware',
    ...其它的中间件
)
Django 1.10 版本 更名为 MIDDLEWARE(单复同形),写法也有变化,详见 第四部分。

如果用 Django 1.10版本开发,部署时用 Django 1.9版本或更低版本,要特别小心此处;

MIDDLEWARE = (
    'zqxt.middleware.BlockedIpMiddleware',
    ...其它的中间件
)

你可能感兴趣的:(python,django)