Django 请求查找以前的引用者 [英] Django request to find previous referrer

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

问题描述

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

 {{request.http referer}} ??<input type="button" value="Back"/>//点击如何调用referrer

解决方案

那条信息在 META 属性,它是 HTTP_REFERER (sic) 键,所以我相信您应该能够在模板中访问它:

{{ request.META.HTTP_REFERER }}

在 shell 中工作:

<预><代码>>>>从 django.template 导入 *>>>t = Template("{{ request.META.HTTP_REFERER }}")>>>从 django.http 导入 HttpRequest>>>请求 = HttpRequest()>>>请求元数据{}>>>req.META['HTTP_REFERER'] = 'google.com'>>>c = Context({'request': req})>>>t.render(c)你'google.com'

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 

解决方案

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 }}

Works in the 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天全站免登陆