I am attempting to use Django rest framework for my server implementation. I get the following error when I attempt to POST.
'WSGIRequest' object has no attribute 'data'
Here is the code for the view.py
from rest_framework import status
from rest_framework.decorators import api_view
from rest_framework.response import Response
from whiteboards.models import Whiteboard, Path, Point
from whiteboards.serializers import WhiteboardSerializer
@api_view(['GET', 'POST'])
def whiteboard_list(request):
"""
List all whiteboards, or create a new whiteboard.
"""
if request.method == 'GET':
print('GET')
whiteboards = Whiteboard.objects.all()
serializer = WhiteboardSerializer(whiteboards, many=True)
return Response(serializer.data)
elif request.method == 'POST':
print('POST')
d = request.data
print('data broke')
serializer = WhiteboardSerializer(data=d)
print("created serializer")
if serializer.is_valid():
serializer.save()
print("It's valid")
return Response(serializer.data, status=status.HTTP_201_CREATED)
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)