python - Django 请求查找以前的推荐人

标签 python django django-models django-views django-templates

我正在将请求传递给模板页面。在 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/

相关文章:

python - 从 Python 中的字典中的列表中删除一个元素

Django:验证具有排除字段的 ModelForm 中的 unique_together 约束

python - 如何在 Django 模型中存储任意数量的字段?

python - Celery-Django 作为守护进程 : Settings not found

python - 与 numpy.gradient 的非均匀间距

python - 将两个数据框与一些共同值合并

django - 弃用 Django 模型中的字段

python - 在管理页面查看相册中的照片

Django 添加不可空字段(ForeignKey)

python - 在 django 中有效地对过滤器查询进行计数