POST method always return 403 Forbidden

前端 未结 7 1653
走了就别回头了
走了就别回头了 2021-02-19 01:46

I have read Django - CSRF verification failed and several questions (and answers) related to django and POST method. One of the best-but-not-working-for-me answer is https://sta

相关标签:
7条回答
  • 2021-02-19 02:18

    I maybe wrong however I found the above solutions rather complex.

    what worked for me was simply including my csrf token into my post request.

    $.ajax({
        type: "POST",
        url: "/reports/",
        data: { csrfmiddlewaretoken: "{{ csrf_token }}",   // < here 
                state:"inactive" 
              },
        success: function() {
            alert("pocohuntus")
            console.log("prototype")
        }
    })
    
    0 讨论(0)
提交回复
热议问题