1👍
so here is what I ended up doing
function getCookie(name) {
let cookieValue = null;
if (document.cookie && document.cookie !== '') {
const cookies = document.cookie.split(';');
for (let i = 0; i < cookies.length; i++) {
const cookie = cookies[i].trim();
// Does this cookie string begin with the name we want?
if (cookie.substring(0, name.length + 1) === (name + '=')) {
cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
break;
}
}
}
return cookieValue;
}
function add_product(data) {
const csrftoken = getCookie('csrftoken');
const config = {
headers: {
'content-type': 'application/json',
'X-CSRFToken': csrftoken,
}
}
axios.post('/products', data, config).then((response) => (alert(response))
}
Source:stackexchange.com