[Answered ]-Redirect after PUT or GET method in Django rest framework

1👍

You can simply use redirect() for redirecting to the desired URL after updating or deleting the article.

Here’s an example:

from django.shortcuts import redirect

class Update(RetrieveUpdateDestroyAPIView):
    queryset = Main.objects.all()
    serializer_class = MainSerializer
    permission_classes = [IsAuthenticated]

    def delete(self, request, *args, **kwargs):
        response = super().delete(request, *args, **kwargs)
        return redirect('/api/')

    def patch(self, request, *args, **kwargs):
        response = super().patch(request, *args, **kwargs)
        return redirect('/api/')

You’ll need to adjust the URL of redirect function accordingly.

Leave a comment