How to redirect to an absolute URL

439 views
Skip to first unread message

Ryan

unread,
Oct 4, 2010, 5:14:00 PM10/4/10
to pylons-discuss
This:
redirect('http://www.website.com')

Will redirect to:
http://www.myapp.com/http://www.website.com

I'd like it to redirect to:
http://www.website.com

Is there an addition argument I can pass to redirect to make it happen?

Gael Pasgrimaud

unread,
Oct 4, 2010, 5:22:31 PM10/4/10
to pylons-...@googlegroups.com
Hi,

Have you tried with a static route ?

http://routes.groovie.org/generating.html#generation-only-routes-aka-static-routes

then:

redirect(url('google'))

--
Gael

> --
> You received this message because you are subscribed to the Google Groups "pylons-discuss" group.
> To post to this group, send email to pylons-...@googlegroups.com.
> To unsubscribe from this group, send email to pylons-discus...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/pylons-discuss?hl=en.
>
>

Ryan

unread,
Oct 5, 2010, 12:11:34 AM10/5/10
to pylons-discuss
Hmmm... seems like a lot of work to set up a route just to do a
redirect. The URL I want to redirect to is absolute, but it's actually
on my domain, so guess I'll just use a regex to put it in relative
form.

On Oct 4, 2:22 pm, Gael Pasgrimaud <g...@gawel.org> wrote:
> Hi,
>
> Have you tried with a static route ?
>
> http://routes.groovie.org/generating.html#generation-only-routes-aka-...

Jason Ross

unread,
Oct 4, 2010, 6:58:50 PM10/4/10
to pylons-discuss
For pylons 1.0 and a redirect executed in a controller action the
following should work-

Note: make sure you set the imports below in the controller file or in
some other module such as, say, helpers.py

from pylons.controllers.util import redirect
from pylons import url


def testController(BaseController):

def test_redirect(self):
return redirect(url('http://www.cnn.com'))

Jason Ross

unread,
Oct 4, 2010, 7:04:26 PM10/4/10
to pylons-discuss
With Pylons 1.0 the following should work:

Note: The imports below should be set in the controller file or in
another module such as, say, helpers.py

......
from pylons.controllers.util import redirect
from pylons import url
.......

def testController(BaseController):

def test_redirect(self):
return redirect(url('http://www.cnn.com'))

On Oct 4, 2:14 pm, Ryan <ryan.mckil...@gmail.com> wrote:

Jason Ross

unread,
Oct 5, 2010, 1:16:08 AM10/5/10
to pylons-discuss
For Pylons 1.0 the following should work -

I'm assuming a controller action. If this is the case you can set-up
the following imports in the controller file

from pylons import url
from pylons.controllers.util redirect

Then within the controller action return the redirect

def TestController(BaseController):

def test_redirect(self):
return redirect(url('http://www.cnn.com'))


Ryan McKillen

unread,
Oct 5, 2010, 11:33:16 AM10/5/10
to pylons-...@googlegroups.com
Just needed to wrap in a url() method. Thanks.
Reply all
Reply to author
Forward
0 new messages