https://stackoverflow.com/questions/13411598/global-variable-not-working-in-python-django
//Global variables are the variables which remain common for the whole applications.Their value can be used across the whole application.
//Session variables are variables which remain common for the whole application but for one particular user. ... But they die when a particular user session ends.The global variable will be accessible by all requests. That means a completely unrelated user will see the previous request's value for that variable. Given that you're using this to access a user's data, this is a serious security risk.
You should store elements like this in the session.
https://www.reddit.com/r/flask/comments/ye834j/global_variable_vs_session_best_practice/
Oh boy, here is something you can try to see what would happen.
Try to use the the website from two different browsers, and switch the browser while testing, you'd notice when the variable is global, your app will basically serve all the users, the details of one of the users, and the value becomes pretty much unpredictable, because all users will affect it.
That's why you generally should never use global variables.
PS: I think sessions are a reasonable solution here.
https://stackoverflow.com/questions/11215554/globals-variables-and-python-multiprocessing
No comments:
Post a Comment