Skip to content

Instantly share code, notes, and snippets.

@akshar-raaj
Created May 7, 2019 06:02
Show Gist options
  • Select an option

  • Save akshar-raaj/2afa99d1d3ef5d685da163e220b4e0dc to your computer and use it in GitHub Desktop.

Select an option

Save akshar-raaj/2afa99d1d3ef5d685da163e220b4e0dc to your computer and use it in GitHub Desktop.
Create Question with QuestionSerializer
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