synergetic
synergetic

Reputation: 8056

wev2py 1.99.2: saving sessions to database

In web2py version 1.99.2, at the beginning of default.py controller I wrote the following:

session.connect(request, response, db, masterapp=None)

I'm using sql server 2008 express edition. In db.py I have:

db = DAL('mssql://sa:mypass@.\SQLEXPRESS/mytest')

Now, sessions are created in the database as expected. Then in default.py controller I added:

@auth.requires_login()
def test():
    return dict()

Also, default/test.html view was created. But, when I try to browse to the default/test.html page it redirects to the user/login page. The problem goes away, if I switch to the default file-based session. What's wrong with my code?

Upvotes: 1

Views: 465

Answers (1)

Anthony
Anthony

Reputation: 25536

Try moving

session.connect(request, response, db, masterapp=None)

to db.py, right after you define the db connection. When auth is defined (I assume you have defined it in db.py or another model file), it needs to have access to the session, so you have to connect to the session first.

Upvotes: 2

Related Questions