RequestHandler Inheritence, passing Parameters to base class

143 views
Skip to first unread message

Amit Shah

unread,
Feb 5, 2013, 9:59:52 AM2/5/13
to python-...@googlegroups.com
Hello all,

I have seen that params can be passed to requesthandler with the use of initialize() method overriding.  However, if we have an inheritence chain, how can parameters be passed to the parent class without passing both parameters to the child class?

class BaseHandler(RequestHandler):
                def initialize(self, SERVICE2):
                    self.service = SERVICE2
                def get(self, username):
                    ...
class MainHandler(BaseHandler):
               def initialize(self,SERVICE1):
                    self.service=SERVICE1
            app = Application([
                (r'/user/(.*)', MainHandler, dict(database=database)),
                ])

Ben Darnell

unread,
Feb 5, 2013, 9:21:44 PM2/5/13
to Tornado Mailing List
The same way you'd do it with a normal constructor instead of initialize():  The subclass's version must also accept the superclass's arguments (or **kwargs) and pass them along to the super() version.

-Ben


--
You received this message because you are subscribed to the Google Groups "Tornado Web Server" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python-tornad...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Reply all
Reply to author
Forward
0 new messages