Bird
0
0

You want to create a custom API endpoint that accepts a URL parameter pk and returns a JSON with the pk value. Which method signature correctly handles this in an APIView?

hard📝 Conceptual Q8 of 15
Django - REST Framework Basics
You want to create a custom API endpoint that accepts a URL parameter pk and returns a JSON with the pk value. Which method signature correctly handles this in an APIView?
Adef get(self, pk):
Bdef get(self, request, pk):
Cdef get(self, request):
Ddef get(self, request, id):
Step-by-Step Solution
Solution:
  1. Step 1: Understand URL parameter passing

    URL parameters like pk are passed as additional arguments to the view method after request.
  2. Step 2: Match method signature

    The method must accept self, request, and pk to access the URL parameter.
  3. Final Answer:

    def get(self, request, pk): -> Option B
  4. Quick Check:

    URL params passed as extra method arguments [OK]
Quick Trick: Add URL params as extra arguments after request [OK]
Common Mistakes:
MISTAKES
  • Omitting pk parameter
  • Using wrong parameter name
  • Not including request parameter

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Django Quizzes