Comment obtenir le jeton CSRF en JavaScript
<input type="hidden" name="csrftoken" value="hgdillksdbgjksdbkvbskb">
Worrisome Wren
<input type="hidden" name="csrftoken" value="hgdillksdbgjksdbkvbskb">
You are not sending the server generated csrf_token for the POST to verify the validity of the data. Hence the error.
As a part of the data part of the request, you need to send the token
csrfmiddlewaretoken: '{{ csrf_token }}'
Something like this
var data = {
url: item.find("#id_url").val(),
title: item.find("#id_title").val(),
tags: item.find("#id_tags").val(),
csrfmiddlewaretoken: '{{ csrf_token }}'
};
Or you could simply do:
var data = $('form').serialize()
if you want to send the whole form as a dictionary
csrftoken = document.mainform.csrftoken.value;
# Do something with the CSRF token, like add dynamic values, like sha256(csrftoken + "dynamicvalue");
document.mainform.csrftoken.value = csrftoken;
<input type="checkbox" class="item-check" name="ssns[]" value="15745253">
<input type="hidden" name="_token" value="GmUW4QXFvoTn3VlXVbQ90N9UGDxohuC1TTwYMzV2">
<input type="checkbox" class="item-check" name="ssns[]" value="15745253">