Django CSRF Check Failing with Ajax Post Request
As outlined in Django's documentation, enabling CSRF protection helps prevent malicious cross-site request attacks. By following the instructions, you attempted to implement the CSRF check with Ajax posting but are still encountering rejection.
To troubleshoot this issue, consider the following steps:
Verify Token Existence:
Ensure that the JavaScript code is fetching the CSRF token and将其存储在称为CSRFTOKON的变量中。在设置标头之前,应该存在此令牌:
$.post("/memorize/", data, function (result) { ... }); var csrftoken = getCookie('csrftoken'); xhr.setRequestHeader("X-CSRFToken", csrftoken);之后,在获取标记,明确的请求中使用ajax neckEnterequestheader的标题,正文:
免责声明: 提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发到邮箱:[email protected] 我们会第一时间内为您处理。
Copyright© 2022 湘ICP备2022001581号-3