Is it correct to say that one should use initialize
method to prepare resources that will be shared by all other methods (e.g. get
, post
, etc) of a RequestHandler subclass?
What are the other common use cases for using initialize
in Tornado? It'd be great to have some examples!
Why you don't like example in tornado code?
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With