How to get the previous url in django

Im askin this again one more time. 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, im using request.META['HTTP_REFERER'].

Any idea or suggestion? I really need it ASAP.

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.


Need Your Help

Node.js HTTP request returns 2 chunks (data bodies)

javascript node.js http httprequest

I'm trying to get the source of an HTML file with an HTTP request in node.js - my problem is that it returns data twice. Here is my code:

Getting illegal character range in regex :java

java regex escaping string-matching

I have a simple regex pattern that verifies names. But When I run it I get illegal character range error. I thought by escaping "\s" it will allow a space but the compiler is still complaining.