Django Rest Framework does not deserialize data passed as raw JSON
django, django-rest-framework
Solution
You're accessing the request data the wrong way - `request.POST` only handles parsing form multipart data.
Use REST framework's `request.data` instead. That'll handle either form data, or json data, or whatever other parsers you have configured.
Problem
I have the following view: ``` class Authenticate(generics.CreateAPIView): serializer_class = AuthSerializer def create(self, request): serializer = AuthSerializer(request.POST) # Do work here ``` This works well if the data is passed as a form, however, if the data is passed as a raw JSON the serializer is instantiated with all it's fields set to None. The documentation does mention that there should be anything specific to processing a raw JSON argument. Any help would be appreciated. UPDATE I have the following work around in order to make the Browsable API work as expected when passing a raw JSON but I believe there must be a better way. ``` def parse_data(request): # If this key exists, it means that a raw JSON was passed via the Browsable API if '_content' in request.POST: stream = StringIO(request.POST['_content']) return JSONParser().parse(stream) return request.POST class Authenticate(generics.CreateAPIView): serializer_class = AuthSerializer def create(self, request): serializer = AuthSerializer(parse_data(request)) # Do work here ```