[Fixed]-How to get the previous URL in Django

12👍

You could work with the request path attribute and add that to your form’s action attribute, like so:

<form method="post" action="/tell-a-friend?return_url={{ request.path }}">
...
</form>

Then, in your tell-a-friend view, HttpResponseRedirect to the return_url query parameter.

1👍

It looks like maybe you are using APPEND_SLASH which will do a redirect if you don’t have a slash. Try changing the button link to sample.com/emailafriend/, note the ending slash.

0👍

Maybe simply pass sample.com/about as GET or POST param? Or even through session.

Leave a comment