LomaxOnTheRun
LomaxOnTheRun

Reputation: 702

DRF custom check_permission not being called

I'm trying to add a custom permission to a view which extends a generic DetailView:

from django.views.generic import DetailView
from rest_framework.permissions import BasePermission


class MyCustomPermission(BasePermission):
    def has_permission(self, request, view):
        return False


class MyView(SomeMixin, DetailView):
    model = MyObject
    template_name = "my_template.html"
    permission_classes = [MyCustomPermission]

    def get_object(self):
        return MyObject.objects.get(id=123)

This should always fail, but it doesn't. I can also put a breakpoint in there (e.g. import pudb; pudb.set_trace()) but that won't ever get hit either.

I know that has_object_permission(...) needs to be explicitely called, but I thought has_permission(...) got called when the view first got called.

Upvotes: 0

Views: 157

Answers (1)

iklinac
iklinac

Reputation: 15758

You are using Django generic DetailView and expecting to behave as DRF views

Upvotes: 4

Related Questions