Django query to find the previous referrer

I submit the request to the template page. In the django template, how to transfer the last page from which the new page was initialized. Instead of history.go (-1) I need to use this

{{request.http referer}} ?? <input type="button" value="Back" /> //onlcick how to call the referrer 
+42
django django-models django-templates django-views
Dec 10 '10 at 6:43
source share
2 answers

This piece of information is in the META attribute of HttpRequest , and it is HTTP_REFERER (sic), so I believe that you should have access to it in the template:

 {{ request.META.HTTP_REFERER }} 

Works in a shell:

 >>> from django.template import * >>> t = Template("{{ request.META.HTTP_REFERER }}") >>> from django.http import HttpRequest >>> req = HttpRequest() >>> req.META {} >>> req.META['HTTP_REFERER'] = 'google.com' >>> c = Context({'request': req}) >>> t.render(c) u'google.com' 
+97
Dec 10 2018-10-10T00:
source share

Rajiv, this is what I do:

  <a href="{{ request.META.HTTP_REFERER }}">Referring Page</a> 
+14
Dec 12 2018-10-12
source share



All Articles