Python Forum
Django don't redirect to an external url - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Web Scraping & Web Development (https://python-forum.io/forum-13.html)
+--- Thread: Django don't redirect to an external url (/thread-6784.html)



Django don't redirect to an external url - PeppePegasus - Dec-07-2017

Hi guys,

I have this view where I execute a redirect to an external site:

def redpagopa(request):
   if request:
       return redirect('http://www.google.com/')
   else:
       return render_to_response('404.html')
....

call=redpagopa(urlpa) # call of the redirect function, redirect doesn't work
where urlpa is the url passed to the function redpagopa..in this code I explicited the address for example google. But the redirect doens't work. If I create an url entry in urls.py:

url(r'^redpagopa/$', 'mopa.views.redpagopa', name='redpagopa')
and in the browser I give the address: http://mysite.com/redpagopa the redirect works. I need when redirect is called, the browser be redirect on the specified url.
More information: I query a SOAP service and the response of this service is an url. So I need to redirect the browser on this url. I call with the instruction call=redpagopa(urlpa) the function to redirect Django (and the browser??) to the passed url.
There is some error in my code? I use Django v1.3.
Thanks.