session in webpy - getting username in all classes

梦想的初衷 提交于 2019-12-03 21:41:23

Just provide the default values for loggedin and username in session's initializer dict. The error seems to appear when those attributes are not set (i.e. when user isn't logged in) and you try to access them.

I have made the following changes in my main.py program.

Changes made : Instead of just giving

session = web.session.Session(app,store,initializer={'login': 0,'privilege': 0,'user':'anonymous','loggedin':False}) 

I added following lines of code,

if web.config.get('_session') is None:
    session = web.session.Session(app,store,initializer={'login': 0,'privilege': 0,'user':'anonymous','loggedin':False})
    web.config._session = session
else:
    session = web.config._session

I also made a small change in initilizer dictionary, inititialized user as anonymous and loggedin as false. Thanks to Andrey for giving me the thread.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!