AttributeError:'WSGIRequest'对象在uwsgi日志中没有属性'user'

时间:2014-11-15 05:48:23

标签: python django python-2.7 nginx uwsgi

我在我的直播服务器中使用带有django和nginx的uwsgi,但它给了我一个错误,即“上游过早关闭连接nginx uwsgi”。谷歌搜索后我发现它不是nginx的问题,而不是uwsgi。因此,我检查了我的uwsgi日志并找到了

    return render(request, 'webclient/404.html')   File
"/usr/local/lib/python2.7/dist-packages/django/shortcuts/__init__.py",
line 49, in render
    context_instance = RequestContext(request, current_app=current_app)   File
"/usr/local/lib/python2.7/dist-packages/django/template/context.py",
line 179, in __init__
    self.update(processor(request))   File "/usr/local/lib/python2.7/dist-packages/django/contrib/auth/decorators.py",
line 24, in _wrapped_view
    if test_func(request.user): AttributeError: 'WSGIRequest' object has no attribute 'user' [pid: 10878|app: 0|req: 6/7] 125.64.35.67 ()
{38 vars in 717 bytes} [Fri Nov 14 10:13:10 2014] GET
/zc/chs/img/body.png =>generated 0 bytes in 3 msecs (HTTP/1.1 500) 0
headers in 0 bytes (0 switches on core 0) [pid: 10878|app: 0|req: 7/8]
127.0.0.1 () {30 vars in 414 bytes} [Fri Nov 14 22:56:41 2014] GET / => generated 0 bytes in 3 msecs (HTTP/1.1 302) 3 headers in 126 bytes (1 switches on core 0)

在这方面,有人可以帮助我吗?

1 个答案:

答案 0 :(得分:0)

更改settings.py中的MIDDLEWARE_CLASSES的顺序即可解决

MIDDLEWARE_CLASSES = (
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
    'BruteBuster.middleware.RequestMiddleware',
    'django.contrib.sites.middleware.CurrentSiteMiddleware',

)