我正在将请求传递给模板页面。在 django 模板中如何传递初始化新页面的最后一页。我需要使用它而不是 history.go(-1)
{{request.http referer}} ??
<input type="button" value="Back" /> //onlcick how to call the referrer
最佳答案
那条信息在META
HttpRequest
的属性,它是 HTTP_REFERER
(sic) 键,所以我相信您应该能够在模板中访问它:
{{ 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'
关于python - Django 请求查找以前的推荐人,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4406377/