0

I have a Flask web app written in Python3. The issue I have though is, that all the variables are always shared between all users that access my website. For example, if user1 during his time on my website clicks a button which in Python3 does var1 = "aaa" and then populates this variable into an HTML input field, then all of the other users accessing the website will see the input field with value aaa.

I'm using gunicorn3 as my WSGI. I have also tried to gunicorn3 python-docx:app -k gevent --worker-connections 1000 but that didn't help at all. (python-docx is the name of my Python3 file)

How can I make sure, that the variables in my Python code are NOT shared between each sessions of different users? I want to make sure, that only the variables and their values are visible to each user specifically, not have them shared like now.

Is it possible?

Thank you very much.

Edit: I do not use database nor do I use a login system for my web app. My web app is public without any user management so anyone can use the web app's functionality for free.

3
  • are you using a database? rather than setting foo = aaa you can query for the users foo in the database and populate with that. Commented Jun 16, 2020 at 9:02
  • I do not use database nor do I use a login system. My web app is public without any user management so anyone can use the web app's functionality.
    – rogaloo
    Commented Jun 16, 2020 at 10:01
  • You can have a look at using sessions to create a unique session for each user on your site. there is a blog post about using session variables here. But this still comes down to needing a database to handle the different data between client sessions. Commented Jun 16, 2020 at 10:19

2 Answers 2

0

The Issue is solved partially if you can identify Users(differentiate requests)

I know you are not using any authentication, so instead you can use timestamp when user requests the page capture the time stamp for that user in dictionary

Instead of using var1="aaa" use: dict['fixed_request_time_stamp']={var1:"aaa"}

So when user request page, a unique time_stamp will created and sent to user along with page, that will submitted back to server when user submit form along with data("aaa") ("timestamp")

-1

This can happen if you have defined the "var1" variable outside of any flask-app functions. This variable became global.

2
  • This turns into an acceptable answer if you propose a solution for the potential problem you have identified. Please avoid the impression to ask a question instead of answering. You can e.g. phrase a conditional answer like "If your problem is ... then the solution is ... because ... ." If you cannot edit accordingly please delete this.
    – Yunnosch
    Commented May 13 at 2:43
  • 1
    This does not provide an answer to the question. Once you have sufficient reputation you will be able to comment on any post; instead, provide answers that don't require clarification from the asker. - From Review
    – CinCout
    Commented May 13 at 16:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.