Bird
0
0

Identify the error in this router registration code:

medium📝 Debug Q14 of 15
Django - REST Framework Basics
Identify the error in this router registration code:
from rest_framework import routers

router = routers.DefaultRouter()
router.register('authors', authorsViewSet)
AThe ViewSet class name should be capitalized as AuthorsViewSet
BThe router should be SimpleRouter, not DefaultRouter
CThe register method requires a third argument for basename
DThe URL prefix 'authors' is invalid
Step-by-Step Solution
Solution:
  1. Step 1: Check the ViewSet class name

    Python class names should be capitalized. 'authorsViewSet' is likely a typo and should be 'AuthorsViewSet'.
  2. Step 2: Validate other options

    DefaultRouter is valid here, basename is optional if ViewSet has queryset, and 'authors' is a valid URL prefix.
  3. Final Answer:

    The ViewSet class name should be capitalized as AuthorsViewSet -> Option A
  4. Quick Check:

    Class names must be capitalized = A [OK]
Quick Trick: Class names must start with uppercase letter [OK]
Common Mistakes:
MISTAKES
  • Using lowercase for class names
  • Thinking basename is always required
  • Confusing router types unnecessarily

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Django Quizzes