From the render_GET
method of a Resource
in twisted
, is it possible to redirect to a different url entirely (hosted elsewhere)
request.redirect(url)
doesn't appear to do anything, and neither does twisted.web.util.Redirect
The equivalent in php would be,
header('location:'.$url);
EDIT
this is the code I'm running
from twisted.web import server, resource
from twisted.internet import reactor
class Simple(resource.Resource):
isLeaf = True
def render_GET(self, request):
request.redirect("www.google.com")
request.finish()
site = server.Site(Simple())
reactor.listenTCP(8080, site)
reactor.run()
I worked it out in the end with help from the other poster, with
request.finish()
, the redirect includinghttp://
and returningNOT_DONE_YET
You should be able to redirect by using
request.redirect(url)
and then callingrequest.finish()
. Please verify that you are callingrequest.finish()
.Location
header requires absolute url e.g.,http://example.com
.302 Found response code says that we SHOULD provide a short hypertext note with a hyperlink to the new URI.
redirectTo()
does exactly that:Or using
Redirect
:Or just using
web
twistd plugin, put inredirect.rpy
file:run:
Just for a demonstration, here's how an implementation of
redirectTo()
could look like: