'WSGIRequest' object has no attribute 'data'
Django REST Framework has its own Request
object that wraps the HttpRequest
object passed in by Django and adds some additional functionality (like custom rendering and another authentication layer). If any properties are accessed on the Request
object that don't exist, it will automatically proxy it to the underlying HttpRequest
, so typically you don't notice the difference.
In DRF 2.x, the Request
property has DATA
and FILES
properties that store the passed in data as well as any files which have been detected. These were combined in DRF 3.0 and replaced with a single data
property. As DRF 3.0 has been released, all of the documentation now reflects the new Request.data
property.
You appear to be using Django REST Framework 2.x, but you are trying to access the new property introduced in DRF 3.0. Because it doesn't exist on the Request
object, it is being proxied down to the HttpRequest
object, where it also isn't being found.
If you're experiencing this issue with a view method then you could try using the @api_view
decorator
from rest_framework.decorators import api_view
@api_view(["POST"])
def Function(request, <other-stuff>):
# do the thing