The session module has another function, session.setup(). This is used to setup the environment in which sessions are stored so that you can separate your session related code from the code which sets up the environment.
To use the database session driver, for example, a number of tables must be setup in the database.
Quick example to setup the sessions database using SQLite:
import sys; sys.path.append('../../../') # show python where the web modules are
import web
import web.database
import web.session
connection = web.database.connect(type='sqlite', database='example-web-session.db')
cursor = connection.cursor()
sessionSetup = web.session.setup(storage='database', cursor=cursor)
errors = sessionSetup.createTables()
if errors:
print '\n'.join(errors)
connection.commit()
The SessionDatabaseSetup object has the following methods:
| ) |
True if all the tables exist, False if any are missing
See About this document... for information on suggesting changes.