[Django]-Post Request Django REST Framework

3👍

In views.py add a new class like this:

class SurveyAPIView(APIView):

    def post(self, request, format=None):
        serializer = SurveySerializer(request.data)
        if serializer.is_valid():
            instance = serializer.save()
            return Response(serializer.data, status=status.HTTP_201_CREATED)
    else:
            return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)

and in urls.py add a new line like:

url(r'^create-survey/$', SurveyAPIView.as_view(),name ='create-survey') ,
👤nmgeek

Leave a comment