storing the db connection somewhere under the active request is the
optimal thing to do -- it makes the db generally accessible throughout
the app.
there are some ways to make it easier to get to:
- if you use a class based approach to writing views, you could have a
base class that does much of the work
- you could write a helper function
class base_class(object):
def dbSession(self):
return self.request.root.db
def getDbSession(request=None):
if not request:
request= get_current_request():
return request.root.db