Py学习  »  LiquidDeath  »  全部回复
回复总数  2

您得到的卷规格无效: C:\Users\user\fin:/fin:rw 在您的生产环境中是因为,主机路径 C:\Users\user\fin 没有。您可以在部署时删除它,或将其更改为生产环境中可用的绝对路径,如下所示。

volumes:
    - '/root:/fin:rw'

其中/root是我的生产环境中可用的目录。

 /path:/path/in/container mounts the host directory, /path at the /path/in/container

 path:/path/in/container creates a volume named path with no relationship to the host.

注意开头的斜线。如果 / 如果存在,它将被视为主机目录,否则它将被视为卷

问题在于设置 http_method_names 属性设置为ModelViewSet。既然你把它设为 get post ,其他方法( put , patch , delete )不会在课堂上工作。要么你必须添加 删去 方法 http_方法_名称 属性或移除整个属性来修复此问题,如下所示。

class UserViewSet(viewsets.ModelViewSet):
    serializer_class = UserSerializer
    queryset = User.objects.all()

    @action(detail=True, methods=['delete'])
    def delete_profile(self, request, pk=None):
        Profile.objects.get(user=pk).delete()
        return Response(status=status.HTTP_204_NO_CONTENT)

如果你不想要别的方法 收到 , 邮递 , 删去 为什么不使用mixins?

更新: 如果不想让delete方法在主视图集上工作,只需覆盖它,如图所示。

 class UserViewSet(viewsets.ModelViewSet):
    serializer_class = UserSerializer
    queryset = User.objects.all() 

    @action(detail=True, methods=['delete'])
    def delete_profile(self, request, pk=None):
         ....

    def destroy(self, request, *args, **kwargs):
        return Response(status=status.HTTP_405_METHOD_NOT_ALLOWED)