以下是錯誤:Python龍捲風 - 如何修復'URLhandler需要完全X參數'的錯誤?
TypeError: __init__() takes exactly 1 argument (3 given)
ERROR:root:Exception in callback <tornado.stack_context._StackContextWrapper object at 0x1017d4470>
Traceback (most recent call last):
File "/Library/Python/2.7/site-packages/tornado-2.4.1-py2.7.egg/tornado/ioloop.py", line 421, in _run_callback
callback()
File "/Library/Python/2.7/site-packages/tornado-2.4.1-py2.7.egg/tornado/iostream.py", line 311, in wrapper
callback(*args)
File "/Library/Python/2.7/site-packages/tornado-2.4.1-py2.7.egg/tornado/httpserver.py", line 268, in _on_headers
self.request_callback(self._request)
File "/Library/Python/2.7/site-packages/tornado-2.4.1-py2.7.egg/tornado/web.py", line 1395, in __call__
handler = spec.handler_class(self, request, **spec.kwargs)
TypeError: __init__() takes exactly 1 argument (3 given)
這裏是代碼:
class IndexHandler(tornado.web.RequestHandler):
def __init__(self):
self.title = "Welcome!"
def get(self):
self.render("index.html", title=self.title)
我已經簡化了代碼到上述情況,我感到莫名其妙,爲什麼這是生產的錯誤。我一定是做錯了,但我不知道什麼(3參數通過??? ...嗯?)
注意:title
變量只是在我的index.html模板中的<title>{{ title }}</title>
。
我正在運行Python 2.7.3,32位版本以便與Mysqldb-Python一起工作。正如你所看到的,我的Tornado版本是2.4.1。我也在OSX Lion上運行(如果這有什麼區別......)也許是最終產生這個錯誤的兼容性問題?
所有的幫助在調試時都會受到讚賞。謝謝。
謝謝你的解釋!我正在學習龍捲風,這對我來說完全有意義。很有幫助。 – JohnZ 2013-02-16 18:31:42
Tornado沒有公開關於'RequestHandler .__ init__'的文檔,因此沒有向後兼容性合約。至少現在我會考慮'初始化'唯一有效的方法。 – 2015-04-28 22:46:16