Python Flask app hosted on PythonAnywhere -how to manage multiple sessions?

Viewed 15

I have an app hosted on PythonAnywhere. App allow users to enter data in the form field, then it print out the modified results. The issue is that when other user enters website, he sees results from the previous users -my goal is that that the every user will have empty results at the beginning. What is the easiest way to handle multiple sessions in this scenario? Thanks!

app.py

from flask import Flask, render_template, request, redirect, url_for

app = Flask(__name__)

input_lists = []


@app.route('/')
def main():
    combined_list = list(dict.fromkeys(input_lists))
    replaced_list = [lst.replace('gl_', '') for lst in combined_list]
    _replaced_list = [lst.replace('_', ' ') for lst in replaced_list]
    return render_template('index.html', content=_replaced_list)


@app.route('/add_list/', methods=['GET', 'POST'])
def add_list():
    if request.method == 'POST':
        lst = request.form.get('gls')
        if len(list(lst)) > 0:
            input_lists.extend(list(lst.split(', ')))
            return redirect(url_for('main'))
0 Answers
Related