在龙卷风中使用self.write代替返回有什么意义?

时间:2013-10-24 10:13:48

标签: python python-2.7 tornado

import tornado.ioloop
import tornado.web

class MainHandler(tornado.web.RequestHandler):
    def get(self):
        return "Hello, world"

application = tornado.web.Application([
    (r"/", MainHandler),
])

if __name__ == "__main__":
    application.listen(8888)
    tornado.ioloop.IOLoop.instance().start()

当我写return而不是self.write时,它会给我一个错误

Traceback (most recent call last):
  File "/home/nishant-un/env/local/lib/python2.7/site-packages/tornado/web.py", line 1155, in _when_complete
    raise ValueError("Expected Future or None, got %r" % result)
ValueError: Expected Future or None, got 'Hello, world'

它不明白这个Values Error究竟是什么意思

我正在使用Tornado 3.1.1

1 个答案:

答案 0 :(得分:2)

在文件中:web.py。函数'get'不返回值,即'return;'您必须使用self.write(“Hello,World”)

def get(self, *args, **kwargs):
    raise HTTPError(405)