Bird
0
0

Identify the error in this DRF permission class:

medium📝 Debug Q6 of 15
Django - DRF Advanced Features
Identify the error in this DRF permission class:
class IsOwner(permissions.BasePermission):
    def has_object_permission(self, request, view, obj):
        return obj.owner == request.user
AMissing import of permissions module
Bhas_object_permission method should return True always
CMethod name should be has_permission instead
DNo error, this is correct
Step-by-Step Solution
Solution:
  1. Step 1: Check permission class correctness

    Method and logic are correct for object-level permission.
  2. Step 2: Identify missing import

    permissions.BasePermission requires importing permissions from rest_framework.
  3. Final Answer:

    Missing import of permissions module -> Option A
  4. Quick Check:

    Missing import = Missing import of permissions module [OK]
Quick Trick: Always import rest_framework.permissions before subclassing [OK]
Common Mistakes:
MISTAKES
  • Thinking method must always return True
  • Confusing has_permission with has_object_permission
  • Assuming no import needed

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Django Quizzes