0

I have the following rest API endpoint:

def post(request, *args, **kwargs):
   print(request.POST)
   short_description = request.POST.get("short_description", "")
   long_description = request.POST.get("long_description", "")

   # rest of the code goes here

when I call

response = client.post("/foo/bar/api/v1/error/1", {"short_description": "hello", "long_description": "world", format='json')

it gives me

<QueryDict: {}>

so both short_description and long_description is empty strings. How can I get that to pass the correct parameters in the POST?

1 Answer 1

1

I think the post method in Django will store data in request.body, please check it

2
  • That was not the case... "You cannot read from body after reading from request's data access" May 23 at 4:42
  • You get an empty string because request.POST does not include 2 fields I think.
    – Nguyen
    May 23 at 4:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.