Xhr всегда отправляет запрос без полезной нагрузки (django

QueryDict всегда является пустым словарем.

Сторона клиента:

function makeRequest (method, url, data, datatype) {

function msg (err, datums) {
  if (err) { throw err; }
  console.log(datums);
}
 var xhr = new XMLHttpRequest();
 xhr.open(method, url,true);
 // X-CSRFToken
 xhr.setRequestHeader('X-CSRFToken', csrftoken);
 // xhr.setRequestHeader('Content-Type',  datatype);
 xhr.setRequestHeader("Content-Type", datatype);
 xhr.onload = function () {
 msg(null, xhr.response);
};
xhr.onerror = function () {
 msg(xhr.response);
};
xhr.send(data);
}

var params = 'orem=ipsum&name=binny';
makeRequest('POST', "http://127.0.0.1:8000/update_student/1/",params
, 'application/x-www-form-urlencoded');

Серверная сторона:

def update_student(request,pk):
    if request.method =="POST":
        print("update_student entered")
        breakpoint()
        return HttpResponse("a post method", status=200)
    else:
        return HttpResponse("This should be a POST method", status=400)

Я наблюдаю за строкой breakpoint() и обнаруживаю, что запрос ничего не отправил. Что случилось? Спасибо:)

p.s. Я ненавижу django. HOw can disable the stupid csrf_token when I'm developing.

Вернуться на верх