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?

7
  • Without knowing what clsmain is I can't say, but something about it smells fishy to me. Commented Oct 9, 2017 at 16:21
  • Why are you using a global variable? Commented Oct 9, 2017 at 16:22
  • @sberry clsmain is a class with common variables and functions. Commented Oct 9, 2017 at 16:28
  • @BrenBarn global variable is used to access clsmain object in another page Commented Oct 9, 2017 at 16:29
  • 2
    Don't use a global variable for that. Use a session variable or some such thing. Commented Oct 9, 2017 at 16:32

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

1 Comment

your link is dead.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.