goo*_*orp 17 django jquery redirect external post-parameter
我正在尝试在Django视图中创建一个重定向到外部URL,并在请求中附加一些get参数.在做了一些环顾四周并尝试了一些之后,似乎我遇到了障碍.
所以我的观点看起来像这样
def view(request):
data = get.data(request)
if something in data:
return HttpResponseRedirect('example.com')
Run Code Online (Sandbox Code Playgroud)
这是我能够得到的.我知道你在请求url中可以指定一些get参数,如下所示:
...
return HttpResponseRedirect('example.com?name=smith&color=brown')
Run Code Online (Sandbox Code Playgroud)
但是由于某些数据很敏感,我不希望它最终出现在网址中.由于它是外部URL,我无法使用接受视图参数的redirect()快捷方式.所以祈祷告诉,一个人如何完成这样的任务?
编辑
在做了一些更多的环顾四周,并在IRC中聊了一下之后,似乎我应该做的是,保持get参数远离用户,包含付款信息,就是将它们作为帖子发送.我被告知你应该能够通过使用一些JS来实现它,可能是jQuery.现在这个问题仍然有点复杂.如何在javascript的帮助下在django中创建帖子重定向?
第二次编辑
好像我被误导了.Thanx用于通过重定向协议DR清除它.在尝试使用重定向来解决此问题时,我似乎一直走错了路.
Ser*_*nko 19
我建议采用以下方法.在您的Django视图/模板返回表单中,浏览器中包含您要作为隐藏表单元素发布的所有参数.表单一加载,JavaScript就会将(POST)表单提交到您想要的位置.
视图:
from django.shortcuts import render_to_response
def view(request):
return render_to_response('test.html', { 'foo': 123, 'bar': 456 })
Run Code Online (Sandbox Code Playgroud)
模板:
<html>
<head>
<title>test</title>
<script type="text/javascript">
function load()
{
window.document.test.submit();
return;
}
</script>
</head>
<body onload="load()">
<form name="test" method="post" action="http://www.example.com">
<input type="hidden" name="foo" value={{ foo }} />
<input type="hidden" name="bar" value={{ bar }} />
</form>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)