扭曲的位置标题重定向 [英] twisted location header redirect
本文介绍了扭曲的位置标题重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
来自资源
的 render_GET
方法 twisted
,是否可以完全重定向到其他网址(在其他地方托管)
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)
似乎没有做任何事情,也没有 twisted.web.util.Redirect
request.redirect(url)
doesn't appear to do anything, and neither does twisted.web.util.Redirect
php中的等价物将是,
The equivalent in php would be,
header('location:'.$url);
编辑
这是代码I来自twisted.web导入服务器的运行
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()
推荐答案
我最后在另一张海报的帮助下解决了这个问题,<$ div c $ c> request.finish(),重定向包括 http://
并返回 NOT_DONE_YET $ c来自twisted.web导入服务器的$ c>
I worked it out in the end with help from the other poster, with request.finish()
, the redirect including http://
and returning NOT_DONE_YET
from twisted.web import server, resource
from twisted.internet import reactor
class Simple(resource.Resource):
isLeaf = True
def render_GET(self, request):
request.redirect("http://www.google.com")
request.finish()
return server.NOT_DONE_YET
site = server.Site(Simple())
reactor.listenTCP(8080, site)
reactor.run()
这篇关于扭曲的位置标题重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文