[Answered ]-Getting how the view was called with HttpRedirect in the next view

2đź‘Ť

âś…

HttpResponseRedirect will literally redirect the user. Basically, it is as if the user had typed in the URL in his browser and pressed enter. Which means some information from the past request won’t be available.

https://docs.djangoproject.com/en/1.10/ref/request-response/#httpresponse-subclasses

You can pass a flag through a GET parameter. It’d do the trick:

HttpResponseRedirect(reverse("tande:holiday") + '?redirect=True')

And then in your form_view read the GET parameters:

if request.GET.get('redirect', None):
    do_something()

You just gotta think what is going to happen if the user intentionally add that GET parameter to the URL. He can fake the result. If your intention is displaying a message then it won’t be a problem.

👤Ev.

Leave a comment