2

Im building a simple api in Django Rest Framework using class based views and the documentation mentions request.data (https://www.django-rest-framework.org/tutorial/2-requests-and-responses/)

from rest_framework.views import APIView
    class myView(APIView):
    def post(self, request):
        print(request.data)

When I try to send post requests either with

  1. curl: curl --data param1=val1&param2=val2 url
  2. djangos browser interface with post (using formatted url and the post option
  3. Advanced Rest Client (chrome add on)

The data of all three appears to end up in request.query_params. When I try to print request.data, however I get an empty response {}

I could just use request.query_params, Im just curious as to how one would get data to go to request.data since it is talked about in the documentation

edit: so curl --data param1=val1&param2=val2 -X POST url sends information to request.data (now if I say request.query_params if get the empty dict {} but request.data contains an object that is the dict query_params.)

1

1 Answer 1

1

curl request doesn't have the -X and POST added. Add these

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.