0

I have stored the userid into a flask session. But when another user opens the browser and sets the session userid. My current session userid changes. Is it possible. I am also using a global class variable which gets initiated from the session as below. Because of this all process gets messed up when more than one user uses the url. I am running python flask using nohup

login
@app.route('/mainlogin',methods = ['GET','POST'])
def login():
    try:
        if request.method =='POST':
            session['uid'] = request.form['db_user']

main
@app.route('/main',methods = ['GET','POST'])
def mainindex():
    global clsmain
    uid=session.get('uid')
    clsmain=clsmain(uid)

@app.route('/viewlog',methods = ['GET','POST'])
def viewlog():
     return render_template('log.html',status="<br>" + clsmain.readlog())

Why does session overwrites. Or is it global variable acting as the same value across sessions?

kten
  • 445
  • 4
  • 13
  • 26

1 Answers1

2

The problem is not with flask session but the global variable. Global variable holds same value across sessions(or flask does not handle global variables based on sessions) . Found reference from this link https://stackoverflow.com/questions/25273989/flask-global-variables-and-sessions

kten
  • 445
  • 4
  • 13
  • 26