This question has been asked before, but those solutions didn't work for me that well:
Proper Django CSRF validation using fetch post request
Right now the content of my post request is correct and being, but the 403 error still shows up.
const url = "/post/create"
let csrftoken = Cookies.get('csrftoken'); //using library
const headers = new Headers({
'X-CSRF-TOKEN': csrftoken
});
return fetch(url, {
method: 'POST',
headers,
credentials: 'same-origin',
mode: 'same-origin',
body: JSON.stringify({
content: content
})
});
Do you have any ideas?
EDIT: This is the solution I found
fetch(url, {
method: 'POST',
mode: "same-origin",
headers: {
"X-CSRFToken": csrftoken,
"Accept": "network/json",
"Content-Type": "network/json",
},
body: JSON.stringify({
content: content
})