[Fixed]-Has_permission() missing 1 required positional argument: 'view'

33👍

You are missing a class instantiation for permissions.IsAuthenticated:

def get_permissions(self):
     if self.request.method in permissions.SAFE_METHODS:
         return (permissions.AllowAny(),)
     return (permissions.IsAuthenticated, IsAuthorOfPost(),)
#                                      ^^^

The error message comes from calling the instance method on IsAuthenticated on the class. Thus request gets mapped to self, view to request and view itself is then missing.

Changing get_permissions() to

def get_permissions(self):
     if self.request.method in permissions.SAFE_METHODS:
         return (permissions.AllowAny(),)
     return (permissions.IsAuthenticated(), IsAuthorOfPost(),)
#                                       ^^

should solve the problem.

As a side note: Your get_permissions() code takes an active role in deciding authorization. It would be better to move this functionality into the permissions themselves to make the code better follow the single responsibility principle.

👤dhke

0👍

In my case, I had written def instead of class while defining the class that inherits from BasePermission

Leave a comment