I
I
idin2018-03-13 23:47:07
Django
idin, 2018-03-13 23:47:07

How to send PUT request in Django (getting CSRF token missing or incorrect error)?

I'm trying to send an ajax request with PUT and I get a CSRF token missing or incorrect response:

console.log(data);
        $.ajax({
            type: 'PUT',
            url: '/comment/',
            data: data,
            dataType: 'json',
            success: function (response) {
                add_comments(response)
            },
            error: function (response) {},
            // complete: function () {
            //     console.log("END")
            // }
        });


in
console log
before sending the object lies
Object { csrfmiddlewaretoken: "cU8JiH3uSdPNXyxxO5ss3GWnRldzQMfj9DGAuvv2OFgLSdbwa63acXVld2CVOFmH", post: 14, comment_title: "666666", comment_text: "777777" }


As I understand it, you need to set some additional settings, or just do you need to disable CTRF for put ??
I have never worked with such a thing, and so far I have little idea how it all turns.
Thank you in advance.
By the way, I found a similar question on Stack Overflow , but I didn’t quite understand from the comments what to do and how it works.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question