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