Use RequestHandler.initialize () cases in Tornado

Is it right to say that you need to use the initialize method to prepare resources that will be used by all other methods (for example, get , post , etc.) of the RequestHandler subclass?

What are the other common uses of initialize in Tornado? It would be great to have some examples!

+4
source share
1 answer

Why don't you like the 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 
+5
source

Source: https://habr.com/ru/post/1435159/


All Articles