Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the previous url in django

Tags:

django

I'll give the step by step info.

Let's say we're in the about page, the url is sample.com/about. There's an email a friend button, when clicked, the url is sample.com/emailafriend. Then when i clicked the submit button, the referal url will be submitted is sample.com/emailafriend. Question, how to get the about page url? BTW, i'm using request.META['HTTP_REFERER'].

like image 504
david Avatar asked Nov 30 '11 13:11

david


1 Answers

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.

like image 57
LaundroMat Avatar answered Oct 16 '22 20:10

LaundroMat