'How to pass error message for custom permission in Django Rest Framework?
I have a custom permission and it called IsVendor. Now I have two built in permission class and they are IsAdminUser, IsAuthenticated and when I try to hit those url without credentials or login information it shows me an error message like this one 'details':'Authentication Credentials are not provided' and I want the same for my custom permission error message. But it is showing Anonymoususer has no object vendor.
class IsVendor(BasePermission):
def has_permission(self, request, view):
if request.user.vendor:
return True
else:
return False
this is my custom permission class. I want to pass error message like 'Authentication Credentials not provided'
Solution 1:[1]
Add message Field
class IsVendor(BasePermission):
message = 'Your Message'
def has_permission(self, request, view):
if request.user.vendor:
return True
else:
return False
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Mohammad sadegh borouny |
