from rest_framework.views import APIView from rest_framework.permissions import IsAuthenticated
class MyView(APIView): permission_classes = [IsAuthenticated]
def initial(self, request, *args, **kwargs):
# 确保调用父类的initial方法
super().initial(request, *args, **kwargs)
# 在initial方法中重新调用dispatch方法以更新权限
self.dispatch(request, *args, **kwargs)
def delete(self, request, pk):
# 删除用户的代码
...
return Response(status=status.HTTP_204_NO_CONTENT)