Jacob Lyles
unread,Nov 23, 2009, 8:03:18 PM11/23/09Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to web.py
Hello,
I'm building a small application using web.py with sqlAlchemy. My
application has users. When a user successfully authenticates, I store
his user ID in the session.user_id variable. Then I query the database
every time I want to render a template using the user's information.
However, this seems wasteful. I've already queried the DB once and
retrieved a "User" sqlalchemy object instance, is there any place I
can store this object without having to recreate it every time I GET a
new page? I tried storing this in a session.user_data variable, but
that caused errors.
Also, every time I query the database I am creating another sqlAlchemy
DB engine and another DB session. Is there a way to share a DB engine
across classes?
So, for instance, I have an URL called '/map' that is linked off the
home page. In the GET method of the MAP class, I am creating a new
sqlAlchemy engine, connecting to it to query for user data, doing the
same for other data, etc. It is the same for all my other URLs.
Thanks,
Jacob