我想學習如何使用python web框架Tornado。我對燒瓶已經很熟悉,但到目前爲止,我甚至無法啓動一個簡單的應用程序。我的目錄結構如下:運行簡單的Python Tornado應用程序時初始化錯誤
- 應用
- 靜態
- 模板
- Testing.html -app.py
我在app.py代碼很簡單:
define("port", default=5000, help="run on the given port", type=int)
class Application(tornado.web.Application):
def __init__(self):
handlers = [
(r"/", MainHandler),
]
settings = dict(
template_path=os.path.join(os.path.dirname(__file__), "templates"),
static_path=os.path.join(os.path.dirname(__file__), "static"),
debug=True,
)
super(Application, self).__init__(handlers, **settings)
class MainHandler(tornado.web.RedirectHandler):
def get(self):
self.render("Testing.html")
if __name__ == "__main__":
http_server = tornado.httpserver.HTTPServer(Application())
http_server.listen(options.port)
tornado.ioloop.IOLoop.current().start()
然而,當我運行app.py我得到的錯誤:
ERROR:tornado.application:Uncaught exception
Traceback (most recent call last):
File "/vt/release/dist/3p/anaconda/lib/python2.7/site-packages/tornado/http1connection.py", line 238, in _read_message
delegate.finish()
File "/vt/release/dist/3p/anaconda/lib/python2.7/site-packages/tornado/httpserver.py", line 289, in finish
self.delegate.finish()
File "/vt/release/dist/3p/anaconda/lib/python2.7/site-packages/tornado/web.py", line 2047, in finish
self.execute()
File "/vt/release/dist/3p/anaconda/lib/python2.7/site-packages/tornado/web.py", line 2067, in execute
**self.handler_kwargs)
File "/vt/release/dist/3p/anaconda/lib/python2.7/site-packages/tornado/web.py", line 187, in __init__
self.initialize(**kwargs)
TypeError: initialize() takes at least 2 arguments (1 given)
這是爲什麼?我應該提到它不會給我錯誤,直到我嘗試連接。
請提供* entire *錯誤消息。應該有一個堆棧跟蹤,顯示整個調用序列。另一端將在您自己的代碼中指明一行。 – Prune
@Prune我添加了完整的消息,它並沒有在我自己的代碼中實際包含一行代碼0123雖然 – klib