Forums

Creating dynamic account

I'm having a serious problem, I created my site for different users to sign up and view their different profiles at same time but what I'm having here is different users viewing the last login profile at same time. I use this

profile_data={}
@app.route("/login", methods=["GET","POST"]
def login():
        global profile_data
        If request.method=="GET":
             return render_template("login.html", profile=profile_data)
        If request.method=="POST":
             profile_data=db_query(email)
             return render_template(home.html, profile=profile_data)

I just typed this code now not exactly what I may have on my script but same ideology. Everything is working fine just that I want different users to access their different profile at same time. Thanks in anticipation

Not sure what is profile_data outside of the view declaration doing, but you set it to global, so it looks like the user who sends a GET request will have access to profile_data set by the last POST request.

Even if it's inside the function same issue will still occur

The problem is related to the fact that this is a global variable.

What should I use instead of global variable. As for session, I think same issue will occur

It will not be the same for session data. Session data is linked to the user that made the request. However, if you want your code to continue to work after you've upgraded, you will need to make sure that your session store is in a database or a file (or anything that is not just in the memory of the worker). It doesn't matter in a free account because you only have one worker.

Help me with a link on how to do that using Python if you have. Thanks a lot

The flask documentation is a good place to start: https://flask.palletsprojects.com/en/2.0.x/api/#sessions

Thanks but it wasn't friendly to me

If you google for "flask sessions" then you may find a tutorial that's more suited to you.