You can do that by using request.META['HTTP_REFERER']
, but it will exist if only your tab previous page was from your website, else there will be no HTTP_REFERER
in META dict
. So be careful and make sure that you are using .get()
notation instead.
# Returns None if user came from another website
request.META.get('HTTP_REFERER')
Note: I gave this answer when Django 1.10 was an actual release. I’m not working with Django anymore, so I can’t tell if this applies to Django 2