我是新来的。为什么要打印“render()”两次?我知道如果我回来服务器尚未完成,它只打印一次,但我希望返回string/JSON。有什么帮助吗?在
代码:
from twisted.web import resource, server
from twisted.internet import reactor
import simplejson
class WResource(resource.Resource):
isLeaf=True
def __init__(self):
print "resource started"
def render(self, request):
print "render()"
request.setHeader('Content-Type', 'application/json')
return simplejson.dumps(dict(through_port=8080, subdomain='hello'))
reactor.listenTCP(9000, server.Site(WResource()))
reactor.run()
输出:
^{pr2}$
因为您的web浏览器正在请求
favicon.ico
。如果您在render
方法中打印request.postpath
,您将看到只有一个请求正在命中您期望的页面。在相关问题 更多 >
编程相关推荐