我有一个类似于the answer here的权限类。
我想在不同条件下设置不同的message
值。我怎么能这样做?
答案 0 :(得分:1)
class UserPermission(permissions.BasePermission):
message = ""
def has_permission(self, request, view):
if some_condetion:
self.message = "some message"
return False
else:
self.message = "other message"
return True
http://www.django-rest-framework.org/api-guide/permissions/#custom-permissions