1csrftoken = document.mainform.csrftoken.value;
2# Do something with the CSRF token, like add dynamic values, like sha256(csrftoken + "dynamicvalue");
3document.mainform.csrftoken.value = csrftoken;
4
1You are not sending the server generated csrf_token for the POST to verify the validity of the data. Hence the error.
2
3As a part of the data part of the request, you need to send the token
4
5csrfmiddlewaretoken: '{{ csrf_token }}'
6Something like this
7
8var data = {
9 url: item.find("#id_url").val(),
10 title: item.find("#id_title").val(),
11 tags: item.find("#id_tags").val(),
12 csrfmiddlewaretoken: '{{ csrf_token }}'
13};
14
15Or you could simply do:
16
17var data = $('form').serialize()
18if you want to send the whole form as a dictionary