我有一个简单的形式,在 django 中使用 csrfmiddlewaretoken 作为:
<form>
{% csrf_token %}
</form>
在页面加载时,表单中的csrfmiddlewaretoken和cookie中的csrftoken是相同的,但是当我使用ctrl + F5刷新页面时,cookie中的csrftoken发生变化,但表单中的csrfmiddlewaretoken保持不变,这会导致 future 的POST AJAX请求失败。
这可能是什么原因?
最佳答案
我认为你的Django版本是1.10或1.11,因为1.9之后,csrf中有一些消息。
To protect against BREACH attacks, the CSRF protection mechanism now changes the form token value on every request (while keeping an invariant secret which can be used to validate the different tokens).
关于jquery - 表单中的csrfmiddlewaretoken和cookie中的csrfotken不同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25920522/