I have a Django project, where I need to send a date string from frontend to backend. At frontend I am using the javascript fetch method
async function getCustomerInDeliveryDate(deliveryDate : String) {
const response = await fetch('getCustomerInTripDate', {
method : 'POST',
headers : {
'Content-Type' : 'application/json',
},
body: JSON.stringify({
deliveryDate : deliveryDate
}),
});
return response
}
From Django backend I currently implemented a simple method that returns a string back to frontend
class GetCustomerInTripDate(LoginRequiredMixin, View):
def post(self, request, *args, **kwargs):
print('Backend received call from front end!!!!!!!!!!!!!')
return JsonResponse({'data': ['hello', 'world']}, status = 200)
The error that I receive when I try to send to backend is
Forbidden (CSRF token missing or incorrect.): /staff/getCustomerInTripDate
I am not sure how to send the csrf token. The research I have done so far all indicated that credentials should be set as "same-origin", and I have tried it but still get the same error.