Created
May 7, 2019 06:02
-
-
Save akshar-raaj/2afa99d1d3ef5d685da163e220b4e0dc to your computer and use it in GitHub Desktop.
Create Question with QuestionSerializer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from rest_framework.decorators import api_view | |
| from rest_framework.response import Response | |
| from rest_framework import status | |
| from .models import Question | |
| from .serializers import QuestionSerializer | |
| @api_view(['GET', 'POST']) | |
| def questions_view(request): | |
| if request.method == 'GET': | |
| return Response("Not Implemented") | |
| elif request.method == 'POST': | |
| serializer = QuestionSerializer(data=request.data) | |
| if serializer.is_valid(): | |
| question = serializer.save() | |
| return Response("Question created with id %s" % (question.id)) | |
| return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment