You can raise ValidationError
from rest_framework.exceptions import ValidationError
class GetFollowers(ListAPIView):
"""
Returns the users who follw user,along with weather the visiter — the one who sent api request —
follows them or they follow him/her
"""
permission_classes = [IsAuthenticated,]
serializer_class = None
def get_queryset(self, *args, **kwargs):
# some code
if not_followed_condition: # I hope you know what you need to check here
raise ValidationError(
{'permission denied': "Can't see user's followers"}
)
# some other code
return queryset
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…