Bird
0
0

How do you correctly register a UserViewSet with a router instance named api_router in Django REST Framework?

easy📝 Syntax Q3 of 15
Django - REST Framework Basics
How do you correctly register a UserViewSet with a router instance named api_router in Django REST Framework?
Aapi_router.add('users', UserViewSet)
Bapi_router.register('users', UserViewSet())
Capi_router.register('users', UserViewSet)
Dapi_router.include('users', UserViewSet)
Step-by-Step Solution
Solution:
  1. Step 1: Understand router.register()

    The register method expects the route prefix and the ViewSet class (not an instance).
  2. Step 2: Correct syntax

    Passing the class without parentheses is correct.
  3. Final Answer:

    api_router.register('users', UserViewSet) -> Option C
  4. Quick Check:

    Use class, not instance, when registering ViewSets [OK]
Quick Trick: Register ViewSet class, not instance, with router [OK]
Common Mistakes:
MISTAKES
  • Calling the ViewSet class (using parentheses)
  • Using non-existent methods like add or include
  • Passing incorrect arguments to register

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Django Quizzes