tags:

views:

273

answers:

1

I'm attempting to use web.py with Tokyo Cabinet / pytc and need to pass the db handle (the connection to tokyo cabinet) to my handler classes so they can talk to tokyo cabinet.

Is there a way to pass the handler to the handler class's init function? Or should I be putting the handle in globals() ? What is globals() and how do you use it?

+1  A: 

The best way would be to add a load hook (described here for sqlalchemy). Define a function that connects to Tokyo Cabinet and adds the resulting db object as an .orm attribute to web.ctx, which is always available inside the controller.

lt_kije