在專案中使用Django自帶的RBAC許可權功能

wellplayed發表於2024-06-21
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='新增成功')

相關文章