CsrfResponseMiddleware

CsrfResponseMiddleware

本文介绍了不正确配置:中间件模块“django.middleware.csrf”没有定义“CsrfResponseMiddleware”类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的本​​地开发环境没有这个问题,但是我刚刚使用nginx + gunicorn(第一次部署应用程序)部署了这个应用程序,当我尝试发出请求时,我收到了这个追溯。 >

I don't have this problem on my local development environment, but I just deployed the app with nginx + gunicorn (first time deploying an app) and I am getting this traceback whenever I try to make a request.

2012-01-21 22:24:36 [5712] [ERROR] Error handling request
Traceback (most recent call last):
  File "/usr/lib/pymodules/python2.7/gunicorn/workers/sync.py", line 96, in handle_request
    respiter = self.wsgi(environ, resp.start_response)
  File "/usr/lib/python2.7/dist-packages/django/core/handlers/wsgi.py", line 219, in __call__
    self.load_middleware()
  File "/usr/lib/python2.7/dist-packages/django/core/handlers/base.py", line 51, in load_middleware
    raise exceptions.ImproperlyConfigured('Middleware module "%s" does not define a "%s" class' % (mw_module, mw_classname))
ImproperlyConfigured: Middleware module "django.middleware.csrf" does not define a "CsrfResponseMiddleware" class

以下是我的settings.py文件的一部分

The following is a part of my settings.py file

MIDDLEWARE_CLASSES = (
    'django.middleware.common.CommonMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.middleware.csrf.CsrfResponseMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
)

任何人都可以指出正确的方向?

Anyone can point me in the right direction?

推荐答案

看起来像部署的服务器有不同版本的Django(旧的)。还有Penthi是对的, CsrfResponseMiddleware 是为了向后兼容,应该被删除。 。

Looks like the server where you deployed has different version of Django (old one). Also Penthi is right, CsrfResponseMiddleware is for backward compatibility and should be removed. https://docs.djangoproject.com/en/1.3/ref/contrib/csrf/#legacy-method.

这篇关于不正确配置:中间件模块“django.middleware.csrf”没有定义“CsrfResponseMiddleware”类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-15 14:01