3

I'm developing an app using webapp2 outside google appengine, I want to integrate sqlalchemy and found an example on http://webpy.org/cookbook/sqlalchemy so I used the models.py from the example and in my main.py I defined my BaseHandler like this:

class BaseHandler(webapp2.RequestHandler):
    @property
    def db(self):
        """ 
        returns ORM handle to the database
        Usage: admin = self.db.query(User).filter_by(name='admin').first()
        """
        return scoped_session(sessionmaker(bind=engine))

My question is that, is this the recommended way to do this? Is their other way?

4

0 回答 0