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
- Django session expiry?
- How can I create an encrypted django field that converts data when it's retrieved from the database?
Source:stackexchange.com