简体   繁体   中英

Python web.py sessions

I am using web.py and trying to get the login working. I want to use a the session for when I login so that on next page reload I could display profile information. The following code is for trying to set the session in the login ajax call

result = db.query("SELECT ...';")

session.client = result[0]
session.logged = True
return session.client

I am using diskStore with the following code

session = web.session.Session(app, web.session.DiskStore('sessions'), initializer={'count': 0})

Afterwards on page load I am trying to get the client from the session and send it to the template but its giving me 'ThreadedDict' object has no attribute 'logged' for the following code:

if session.logged == True:
    client = session.get('client')
return self.render.loginPage("Profile", client)

What is wrong please?

i think you forgot to store the session obect in the configuration like describeed here :

if web.config.get('_session') is None:
    session = web.session.Session(app, web.session.DiskStore('sessions'), {'count': 0})
    web.config._session = session
else:
    session = web.config._session

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM