说一个人应该使用initialize
方法准备将由RequestHandler子类的所有其他方法(例如get
,post
等)共享的资源是否正确?
在Tornado中使用initialize
的其他常见用例还有哪些?举几个例子真是太好了!
最佳答案
为什么不喜欢example in tornado代码?
def initialize(self):
"""Hook for subclass initialization.
A dictionary passed as the third argument of a url spec will be
supplied as keyword arguments to initialize().
Example::
class ProfileHandler(RequestHandler):
def initialize(self, database):
self.database = database
def get(self, username):
...
app = Application([
(r'/user/(.*)', ProfileHandler, dict(database=database)),
])
"""
pass
关于python - Tornado中RequestHandler.initialize()的用例,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/12503810/