Python Django REST Framework RESTful Django Create a ListView with a POST

Dmitriy Shubenok
Dmitriy Shubenok
130 Points

What is wrong?

What is wrong?

scorekeeper/views.py
from rest_framework.response import Response
from rest_framework.views import APIView

from . import models
from . import serializers


class GameListCreate(APIView):
    def get(self, request, format=None):
        games = models.Game.objects.all()
        serializer = serializers.GameSerializer(games, many=True)
        return Response(serializer.data)

    def post(self, request, format=None):
        serializer = serializers.GameSerializer(data=request.data)
        serializer.is_valid(raise_exception=True)
        serializer.save()
        return Response(serializer.data, status=status.HTTP_201_CREATED)

1 Answer

KRIS NIKOLAISEN
PRO
KRIS NIKOLAISEN
Pro Student 32,991 Points

You need to import status as well

from rest_framework import status