Complete the code to import the Django REST Framework module for serializers.
from rest_framework import [1]
The serializers module in DRF helps convert complex data like Django models into JSON format for APIs.
Complete the code to create a simple API view using DRF's generic views.
from rest_framework import generics class BookList(generics.[1]): queryset = Book.objects.all() serializer_class = BookSerializer
ListAPIView provides a read-only endpoint to list all objects, perfect for showing all books.
Fix the error in the serializer by completing the field declaration.
from rest_framework import serializers class BookSerializer(serializers.Serializer): title = serializers.[1](max_length=100)
CharField is used for text fields like a book's title.
Fill both blanks to create a view that allows listing and creating books.
from rest_framework import generics class BookListCreate(generics.[1], generics.[2]): queryset = Book.objects.all() serializer_class = BookSerializer
Combining ListAPIView and CreateAPIView allows the view to list all books and create new ones.
Fill all three blanks to write a serializer that validates a book's title length and includes an author field.
from rest_framework import serializers class BookSerializer(serializers.Serializer): title = serializers.[1](max_length=100) author = serializers.[2](max_length=50) def validate_title(self, value): if len(value) < [3]: raise serializers.ValidationError("Title too short") return value
Both title and author are text fields, so use CharField. The minimum title length is set to 5.