0
0
Djangoframework~10 mins

APIView for custom endpoints in Django - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to import the base class for creating a custom API view.

Django
from rest_framework.views import [1]
Drag options to blanks, or click blank then click option'
AAPIView
BViewSet
CGenericView
DModelViewSet
Attempts:
3 left
💡 Hint
Common Mistakes
Importing ViewSet instead of APIView
Using ModelViewSet which is for models, not custom endpoints
Confusing GenericView with APIView
2fill in blank
medium

Complete the method name to handle GET requests in a custom APIView.

Django
class MyView(APIView):
    def [1](self, request):
        return Response({'message': 'Hello'})
Drag options to blanks, or click blank then click option'
Apost
Bget
Cput
Ddelete
Attempts:
3 left
💡 Hint
Common Mistakes
Using post instead of get for GET requests
Using uppercase method names
Forgetting to include self and request parameters
3fill in blank
hard

Fix the error in the import statement to use the Response class correctly.

Django
from rest_framework.[1] import Response
Drag options to blanks, or click blank then click option'
Aresponse
Bserializers
Cviews
Attempts:
3 left
💡 Hint
Common Mistakes
Importing Response from views
Using plural 'responses' instead of 'response'
Confusing with serializers module
4fill in blank
hard

Fill both blanks to define a POST method that returns a JSON message with status 201.

Django
class CreateView(APIView):
    def [1](self, request):
        return Response({'message': 'Created'}, status=[2])
Drag options to blanks, or click blank then click option'
Apost
Bget
C201
D200
Attempts:
3 left
💡 Hint
Common Mistakes
Using get instead of post for POST requests
Using status 200 instead of 201 for creation
Forgetting to include status parameter
5fill in blank
hard

Fill all three blanks to create a custom APIView with a GET method returning a welcome message.

Django
from rest_framework.views import [1]
from rest_framework.response import [2]

class WelcomeView([3]):
    def get(self, request):
        return Response({'message': 'Welcome!'})
Drag options to blanks, or click blank then click option'
AAPIView
BResponse
DViewSet
Attempts:
3 left
💡 Hint
Common Mistakes
Importing Response from wrong module
Subclassing ViewSet instead of APIView
Using wrong class names or typos