Skip to content

Instantly share code, notes, and snippets.

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

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

Select an option

Save akshar-raaj/0ea1d359c13842a5e947f66172477926 to your computer and use it in GitHub Desktop.
List Questions
@api_view(['GET', 'POST'])
def questions_view(request):
if request.method == 'GET':
questions = Question.objects.all()
serializer = QuestionSerializer(questions, many=True)
return Response(serializer.data)
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