在项目中使用Django自带的RBAC权限功能
from rest_framework_simplejwt.authentication import JWTAuthentication
from rest_framework.permissions import IsAuthenticated, DjangoModelPermissions
class EditDailyTimeslotView(GenericViewSet):
authentication_classes = [JWTAuthentication]
# 在类中配置
permission_classes = [IsAuthenticated, DjangoModelPermissions]
# 或者在action中配置
@action(methods=['POST'], detail=False, permission_classes=[DjangoModelPermissions])
def add(self, request):
return APIResponse(msg='添加成功')

浙公网安备 33010602011771号