classQuiz(models.Model): title = models.CharField(max_length=200) body = models.TextField() answer = models.IntegerField()
시리얼라이저 생성하기
quiz/serializers.py
from rest_framework import serializers from .models import Quiz
classQuizSerializer(serializers.ModelSerializer): classMeta: model = Quiz fields = ('title', 'body', 'answer')
시리얼라이저는 장고의 model데이터를 JSON형태로 만들어주는 코드이다. api통신이 가능하게 해준다.
반환 값 설정하기
quize/views.py
from rest_framework.response import Response from rest_framework.decorators import api_view from .models import Quiz from .serializers import QuizSerializer
from rest_framework.response import Response from rest_framework.decorators import api_view from .models import Quiz from .serializers import QuizSerializer import random