我们的应用程序发布用户数据,然后获得成功或拒绝回复。成功响应将带有如下URL:
b'SUCCESS|http://examplesite.com/m.cfm?t=17&wm_login=info&gouser=50105E5C440'
问题是当我在python中拆分这些数据时,我可以将用户发送到URL python对此URL进行编码,使其不再有效。
没有服务器错误消息,而是重定向网址中出现错误:
http://examplesite.com/m.cfm?t=17&wm_login=info&gouser=50105E5C440
注意&转换为&
我尝试了类似问题的无解决方案,但似乎没有任何东西将用户重定向到未编码的URL。得到我的部分是,当我打印()重定向网址时,它实际显示正确的网址!
views.py
def iframe1(request):
ip = get_real_ip(request)
created = timezone.now()
if request.method == 'POST':
form = LeadCaptureForm1(request.POST)
if form.is_valid():
# Save lead
lead = form.save(commit=False)
lead.created = created
lead.birth_date = form.cleaned_data.get('birth_date')
lead.ipaddress = get_real_ip(request)
lead.joinmethod = "Iframe1"
lead.save()
# API POST and save return message
payload = {
...
}
r = requests.post(url, payload)
print(r.status_code)
print(r.content)
api_status1 = r.content.decode("utf-8").split('|')[0]
api_command1 = r.content.decode("utf-8").split('|')[1]
print(api_status1)
print(api_command1)
#backup_link = "https://govice.online/click?offer_id=192&affiliate_id=7&sub_id1=API_Backup-Link"
backup_link = "http://viceoffers.com"
lead.xmeets = r.content
lead.save()
# Redirect lead to Success URL
if "http" in api_command1:
return TemplateResponse(request, 'leadwrench/redirect_template.html', {'redirect_url': api_command1, 'api_status1': api_status1})
else:
return TemplateResponse(request, 'leadwrench/redirect_template.html', {'redirect_url': backup_link})
redirect_template.html
<html>
<head>
<meta http-equiv="refresh" content="5; url={{ redirect_url }}" />
<script>
window.top.location.href = '{{ redirect_url }}';
</script>
</head>
<body>
<p>api_status1: {{ redirect_url }}</p>
<p>api_command1: {{ api_command1 }}</p>
</body>
</html>
答案 0 :(得分:3)
默认情况下,Django将执行模板参数的HTML转义,其中(除其他外)将&
更改为&
。使用模板中的safe模板过滤器来避免:
<html>
<head>
<meta http-equiv="refresh" content="5; url={{ redirect_url|safe }}" />
<script>
window.top.location.href = '{{ redirect_url|safe }}';
</script>
</head>
<body>
<p>api_status1: {{ redirect_url }}</p>
<p>api_command1: {{ api_command1 }}</p>
</body>
</html>