Hi,

Looks like your code that calls POST data is incorrect. As you see in printout for some reason included data is strangely wrapped as an object to toplevel item_id.


On 10.03.2017 15:27, Sandesh Naroju wrote:
I just want to try simple Django rest framework code, I used APIVIEW and posted data through browser.

CODE:

    class GetData(APIView):

        def post(self, request, format=None):
            if request.method == 'POST':
                item_id = request.data.get('item_id')
                return Response({"return": "OK ","item_id":item_id})
            else:
                return Response({"return": "NOT OK "})


The above code should echo the item_id whatever i "POST"ed. but the result is always null.

POST data:

    {
     "item_id" : "3456787"
    }

result:

    {
        "item_id":null,
        "return" :"OK "
    }

I don't understand where I went wrong. the above code works fine in my loaclhost but does not work in production server.

I tried to print request.data which gives me this

{ "item_id": { "_content_type": "application/json", "_content": "{\r\n\r\n\"item_id\" : \"3456787\"\r\n\r\n}" }, "return": "OK " }

--
You received this message because you are subscribed to the Google Groups "Django REST framework" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected] <mailto:[email protected]>.
For more options, visit https://groups.google.com/d/optout.

--
Jani Tiainen

--
You received this message because you are subscribed to the Google Groups "Django 
REST framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to