Hi, I am new to use Django and this is my first project. The request data works okay however the serializer data is empty and I don’t know how to solve it. I used heroku to deploy my project, I am not sure whether it is related.
Here is my serializer
> class CreateRoomSerializer(serializers.ModelSerializer):
class Meta:
model = Room
fields = ('guest_can_pause', 'votes_to_skip')
Here is my view
class CreateRoomView(APIView):
serializer_class=CreateRoomSerializer
def post(self, request, format=None):
if not self.request.session.exists(self.request.session.session_key):
self.request.session.create()
serializer = self.serializer_class(data=request.data)
print(request.data)
if serializer.is_valid():
# serializer.save()
print(serializer.data)
print(request.data)
print(serializer.data.get('guest_can_pause'))
print(serializer.data.get('votes_to_skip'))
guest_can_pause=serializer.data.get('guest_can_pause')
votes_to_skip=serializer.data.get('votes_to_skip')
print(guest_can_pause)
print(votes_to_skip)
Here is the result I got
2022-04-03T15:55:24.114792+00:00 app[web.1]: {'method': 'POST', 'headers': {'Content-Type': 'application/json'}, 'body': '{"votes_to_skip":2,"guest_can_pause":true}'}
2022-04-03T15:55:24.117254+00:00 app[web.1]: {}
2022-04-03T15:55:24.117261+00:00 app[web.1]: {'method': 'POST', 'headers': {'Content-Type': 'application/json'}, 'body': '{"votes_to_skip":2,"guest_can_pause":true}'}
2022-04-03T15:55:24.117264+00:00 app[web.1]: None
2022-04-03T15:55:24.117896+00:00 app[web.1]: None
2022-04-03T15:55:24.117934+00:00 app[web.1]: None
2022-04-03T15:55:24.117973+00:00 app[web.1]: None
So the data is received, however, the serilizer.data is still empty.