I am trying to send data from React via axios to the Django.
Here is the code on the React Side:
axios.defaults.xsrfHeaderName = "X-CSRFTOKEN";
axios.defaults.xsrfCookieName = "csrftoken";
axios.defaults.withCredentials = true
sendData = () => {
let formData = new FormData()
formData.append('picture', this.state.files.height, this.state.files.name)
axios.post("/api/async_function/", formData, {
headers: { 'accept': 'application/json','content-type': 'multipart/form-data'
},}).then(resp => { console.log(resp)}) }
Here is the code on Django Side:
async def async_function(request, *args, **kwargs):
if request.method == 'POST':
print(request.POST)
Basically, the request.POST.get and request.POST are empty and return <QueryDict: {}>. Can someone help on why it is empty?