Home > Back-end >  django request.POST.items() returns empty list everytime with Postman
django request.POST.items() returns empty list everytime with Postman

Time:02-04

I have a django method and I'm just trying to pull out a POST variable:

@csrf_exempt
def update_backer(request):
    for k, v in request.POST.items():
        print(k, v)

    email = request.POST.get("email", "none")

    return JsonResponse({"data":{
        "email":email
    }})

When I try to do a POST via javascript XMLHttpRequest, I wasn't getting the data through. So I fell back to Postman to try to confirm things are working on the django end. And I am posting the data, but django isn't seeing it. Am I doing something obviously wrong?

enter image description here

Edit: Interestingly enough, if I change it to GET instead of POST, it works as I would expect.

CodePudding user response:

For POST request values are sent in request body. You can use application/x-www-form-urlencoded content type so that request body has same format of query params.

enter image description here

  •  Tags:  
  • Related