在龙卷风中使用self.write intsead of return有什么意义


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()

当我写返回而不是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到底是什么意思

我正在使用龙卷风 3.1.1

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

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

相关内容

最新更新