Hi there,
I was wondering if anyone could help me out with this. I'm noticing a difference between Flask deals with global variables on PythonAnywhere initialized inside of if name == "main": compared with my local version.
e.g. the following will not work on PythonAnywhere but works locally i.e. my_list when sent to index.html will be empty.
from flask import Flask, render_template
app = Flask(__name__)
my_list = []
@app.route("/index")
def render_foo():
return render_template("index.html", my_list=my_list)
if __name__ == "__main__":
global my_list
my_list.append(0)
my_list.append(1)
app.run()
If I change it to the following it works:
@app.route("/index")
def render_foo():
global my_list
my_list.append(0)
my_list.append(1)
return render_template("index.html", my_list=my_list)
if __name__ == "__main__":
app.run()
Thanks in advance for the help.