I do a request to my local server using postman like this:
As you can see it's a post request. In my view (APIView
) I need access to the json data. But when I try:
request.POST
# <QueryDict: {}>
or
request.data # ¿?
# AttributeError: 'WSGIRequest' object has no attribute 'data'
The only way I can see the sent data is when I access to
request.body
# '{\n "token": "6J3qG4Ji2Jw44eIklKvPYxUgclfGRWHZDKG",\n "city": "Port Orange",\n "state": "FL",\n "formatted_address": "Peach Blossom Blvd 5329",\n "_zip": "32128"\n}'
But this is a 'str'
>>> type(request.body)
<type 'str'>
I an trying to access to the request's data in dispatch()
method. I can do this:
req = self.initialize_request(request)
This returns a rest_framework.request.Request
object and I can access to request data. But then I can't call
super(FaveoAPIView, self).dispatch(request, *args, **kwargs)
Because I get:
{
"status_code": 400,
"object": "Malformed request.",
"success": false
}
I can'r understand why, I guess that when I call self.initialize_request()
something change. Any idea?