Passing parameters to a webapp2.RequestHandler object in python
Question: Is there any way to pass parameters to a RequestHandler object when I create
my WSGIApplication instance?

I mean

    
    
    app = webapp2.WSGIApplication([
        ('/', MainHandler),
        ('/route1', Handler1),
        ('/route2', Handler2)
    ], debug=True)
    

Is it possible to pass some arguments to `MainHandler`, `Handler1` or
`Handler2`?

Thanks in advance


Answer: You can also pass parameters through a configuration dictionary.

First you define a configuration:

    
    
    import webapp2
    
    config = {'foo': 'bar'}
    
    app = webapp2.WSGIApplication(routes=[
        (r'/', 'handlers.MyHandler'),
    ], config=config)
    

Then access it as you need. Inside a RequestHandler, for example:

    
    
    import webapp2
    
    class MyHandler(webapp2.RequestHandler):
        def get(self):
            foo = self.app.config.get('foo')
            self.response.write('foo value is %s' % foo)
    

From here: [webapp2 v2.5.1 documentation](http://webapp-
improved.appspot.com/guide/app.html#guide-app-config)

