Complete the code to import the main DRF class for creating API views.
from rest_framework.views import [1]
The APIView class is the base class for creating API views in DRF.
Complete the code to add pagination to a DRF view.
from rest_framework.pagination import [1]
PageNumberPagination is a common pagination class that divides results into pages.
Fix the error in the serializer by completing the field declaration.
class UserSerializer(serializers.Serializer): email = serializers.[1](max_length=100)
EmailField validates that the input is a valid email address.
Fill both blanks to create a viewset with a custom queryset and serializer.
class ProductViewSet(viewsets.[1]): queryset = Product.objects.[2]()
ModelViewSet provides full CRUD operations, and all() returns all products.
Fill all three blanks to define a serializer with a nested serializer and a custom validation method.
class AddressSerializer(serializers.Serializer): street = serializers.CharField(max_length=100) class UserSerializer(serializers.Serializer): name = serializers.CharField(max_length=50) address = [1]() def validate_name(self, value): if len(value) < [2]: raise serializers.ValidationError("Name too short") return value def validate(self, data): if data['name'] == 'admin' and data['address']['street'] == [3]: raise serializers.ValidationError("Admin cannot live on this street") return data
AddressSerializer() defines a nested serializer for the address field. The minimum name length is 5, and admin users cannot live on "Forbidden Street".