Our app POSTS user data and then get's a success or rejected response. The success response will come with a URL like such:
b'SUCCESS|http://examplesite.com/m.cfm?t=17&wm_login=info&gouser=50105E5C440'
The issue is when I split this data in python to so I can send users to the URL python encodes this URL so it no longer works.
There is no server error message but rather the error is apparent in the redirect URL:
http://examplesite.com/m.cfm?t=17&wm_login=info&gouser=50105E5C440
Notice the & gets converted to &
I have tried contless solution to similar problems but nothing seems to redirect the user to an uncoded URL. The part that get's me is that when I print() the redirect URL it actually shows the right one!
- The reason I redirect to a page first is that this form is an iframe and otherwise the Parent page does not get redirected.
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>