Django - CSRF token missing or incorrect

前端 未结 4 1971
失恋的感觉
失恋的感觉 2021-01-04 02:57

I just updated my django to 1.4. But I am getting the following error when I try to submit my login form:

Forbidden (403) CSRF verification failed.

相关标签:
4条回答
  • 2021-01-04 03:36

    I had similar issue where my app was deployed on HTTPS. I had to change setting flag CSRF_COOKIE_HTTPONLY to false so client server can access csrf cookie.

    0 讨论(0)
  • 2021-01-04 03:41

    Clearing the Browser or Google Chrome cookies, I hope it will work.

    0 讨论(0)
  • 2021-01-04 03:51

    The code looks fine, Django 1.3 and 1.4 auth.views.login uses RequestContext correctly. Please check:

    • Firstly clear data of browser and try again
    • What's the value of submitted csrfmiddlewaretoken
    • Do you import correct Django?
    • Just make sure, is there UserWarning in console like?: "A {% csrf_token %} was used in a template, but the context did not provide the value. This is usually caused by not using RequestContext."
    0 讨论(0)
  • 2021-01-04 04:02
    1. For 1.3 and 1.4, "django.middleware.csrf.CsrfResponseMiddleware" should be named "django.middleware.csrf.CsrfViewMiddleware"
    2. Also, for me clearing Google Chrome's cookies made it work.
    0 讨论(0)
提交回复
热议问题