Django请求查找以前的引荐来源 [英] Django request to find previous referrer

查看:109
本文介绍了Django请求查找以前的引荐来源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将请求传递给模板页面。在django模板中如何传递新页面初始化的最后一页。不需要history.go(-1)我需要使用这个

I am passing the request to the template page.In django template how to pass the last page from which the new page was initialised.Instead of history.go(-1) i need to use this

 {{request.http referer}} ??

 <input type="button" value="Back" /> //onlcick how to call the referrer 


推荐答案

信息位于 META HttpRequest 的$ c> 属性,它是 HTTP_REFERER (sic)键,所以我相信您应该可以在模板中访问它:

That piece of information is in the META attribute of the HttpRequest, and it's the HTTP_REFERER (sic) key, so I believe you should be able to access it in the template as:

{{ request.META.HTTP_REFERER }}

在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'

这篇关于Django请求查找以前的引荐来源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆