ImproperlyConfigured: Middleware module “django.middleware.csrf” does not define a “CsrfResponseMiddleware” class

后端 未结 3 1232
庸人自扰
庸人自扰 2021-01-13 13:42

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 traceba

相关标签:
3条回答
  • 2021-01-13 13:51

    In Django 1.4, you should remove the 'django.middleware.csrf.CsrfResponseMiddleware', because it can cause security problems.

    Furthermore, two things must be done.

    1. Add a {% csrf_token %} tag to your post form.
    2. Use RequestContext instead of Context in all of your relative views.py files.
    0 讨论(0)
  • 2021-01-13 13:56

    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.

    0 讨论(0)
  • 2021-01-13 14:07

    In Django 1.3, I have only django.middleware.csrf.CsrfViewMiddleware in my middlewares to get CSRF protection working

    0 讨论(0)
提交回复
热议问题