[Python] Success message not showing after deleting the object in Django rest framework

Discussão em 'Python' iniciado por Stack, Fevereiro 9, 2025.

  1. Stack

    Stack Membro Participativo

    I have a DestroyAPIView in which I am using the perform_delete function to delete an instance. However, I want to send a success message with 200 status. I tried, but in the postman I am getting blank with 204 status. How can I achieve this?

    My view:

    class UpdateOrderView(UpdateAPIView,DestroyAPIView):
    permission_classes = [AllowAny]
    #queryset = Order.objects.prefetch_related('order_items').all()
    #value = self.kwargs['pk']
    queryset = Order.objects.all()
    print(queryset)
    serializer_class = OrderUpdateSerializer

    def perform_destroy(self, instance):
    if instance.delete():
    return Response({
    "message":"Order deleted successfully"
    },
    status=status.HTTP_200_OK)
    else:
    pass


    The instance is deleted, I have checked the database, but I am not getting success message.

    Continue reading...

Compartilhe esta Página