In my Django project, I have a task that involves sending a date string from the frontend to the backend. On the frontend, I am utilizing JavaScript's 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
}
In the Django backend, I have a basic method set up that currently returns a string to the 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)
Upon attempting to send data to the backend, I encounter the following error:
Forbidden (CSRF token missing or incorrect.): /staff/getCustomerInTripDate
I'm unsure how to include the CSRF token. The information I've found suggests setting credentials as "same-origin", which I've tried but still receive the same error message.