python - Is there a way to modify the HTTP_REFERRER before redirecting in Django?
问题描述
Let's say someone is on www.yahoo.com, and then hits my URL www.mysite.com. Now, in Django, I want to do:
return HttpResponseRedirect('https://www.google.com')
However, when Google receives this request, they will see the HTTP_REFERER was Yahoo, but I want to modify the referer so it shows ‘www.mysite.com’. Can this be done?
解决方案
您应该能够执行以下操作:
resp = HttpResponseRedirect('https://www.google.com')
resp['HTTP_REFERER'] = 'www.mysite.com'
return resp
这是因为HttpResponseRedirect
是 的子类HttpResponse
,因此您可以像设置标题字段一样设置HttpResponse
推荐阅读
- hibernate - 不使用 GET 或 LOAD 获取单个域类对象
- r - 如何计算一行中的数值数量
- swift - 更改自定义 UITableViewCell 类中的项目
- ios - 如何增加特定部分中特定单元格的高度
- android - 我应该怎么做才能让我的应用程序运行更流畅?
- ionic-framework - 如何仅在特定视图中添加 < ion-menu >?
- mariadb - 如果存在则更改列
- facebook-graph-api - Facebook SDK 无效范围错误
- c - 何时执行程序和共享库之间的动态链接?
- java - 无法使用 SQLite 数据库中的数据填充 ListView