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':
        return HttpResponse("Good!")
        return HttpResponse("Bad.")

Console Development Server

None <<<<

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

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) {
   var username = document.getElementById("username").value;

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

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