pythondjangorestdjango-rest-frameworkdjango-views

django: request.POST is empty


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?


Solution

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