3

How do I find the previous URL that referred to the current one in Django?

For example, I want different output from my home page if it was referred from the login page or from the sign up page or from elsewhere?

I can see what I want in the Referer section of Request Headers in Chrome Developer Tools, but I can't seem to access the value using request.referer.

I don't want to append the referer using index.html?return_url={{ request.path }} because I'm not certain where it's coming from.

3

1 Answer 1

9

You can use self.request.META['HTTP_REFERER'], more useful meta headers in the docs

previous_url = self.request.META.get('HTTP_REFERER')

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.