Django how to redirect pagination page after update data?

I find the solution after struggling lot of hours. Here I am sharing the code. Hope it will help others.

I added this success url in my update view:

def get_success_url(self):

        res = reverse('blog-admin')

        if 'page' in self.request.GET:

            res += f"?page={self.request.GET['page']}"

        return res

I added this mini forms in my list view. Basically this forms taking me to the update page after click on button.

<form method="POST" action="{% url 'comment-approve' pk=blogcomment.pk %}?page={{ page_obj.number }}">{% csrf_token %}<input type="submit" value="{{ blogcomment.name }}"></form>

After finishing edit it redirecting me on pagination page where I opened the update view. Such as if I opened it from page 5 then it will redirect me to page 5 from update page.

1 Like