Django Post request not receiving data | بلاگ

Django Post request not receiving data

تعرفه تبلیغات در سایت

آخرین مطالب

امکانات وب

Vote count: 0

I've spent hours looking up this issue with no avail.

I am having issue with post data from an html page I am sending {'username': 'username'} but when I do request.POST.get('username') it returns none, I alos tried {username, 'username'}

def test_post(request):
    if request.method == 'POST':
        print(request.POST.get('username'))
        return HttpResponse("Good!")
    else:
        return HttpResponse("Bad.")

Console Development Server

None <<<<

[12/Feb/2018 19:39:53] "POST /test_post HTTP/1.1" 200 5
(edited)

I am sending the data as {'username': 'username'} That works correctly how come I am unable to get it to show up?

This is the Javascript code that calls from the page:

document.getElementById('submit').addEventListener('click', function(e) {
    e.preventDefault();
   var username = document.getElementById("username").value;

   data = {gitusername: username};
   console.log(data);
   var request = new XMLHttpRequest();
   request.open('POST', '/getuser', true);
   request.setRequestHeader('Content-Type', 'x-www-form-urlencoded');
   request.send(data);
});
asked 1 min ago
ChrisEthanFox

...
نویسنده : استخدام کار بازدید : 7 تاريخ : سه شنبه 24 بهمن 1396 ساعت: 7:28