I've written the following flask server:
from flask import Flask, render_template, request
import os
app = Flask(__name__)
# home
@app.route('/')
def home():
return 'HOME PAGE'
@app.route('/add')
def add():
global a
a += 1
return str(a)
if __name__ == '__main__':
a = 0
HOST = '10.10.10.10'
PORT = 5555
app.run(HOST, PORT)
Considering there are two users (from different IP addresses) of my server: A and B. When user A requests by url 10.10.10.10:5555/add, he gets the result 1. After that, if user B requests by url 10.10.10.10:5555/add he will get 2. Because two users share the same variable a
However, I want my server to handle A and B separately which means a user A and B have a variable a in their own way. The requests of A shouldn't affect the result that B will get. For example, When user A requests, he gets 1. After that user B requests and he should get 1 as well.
How should I modify my code to achieve this?