so i’m creating simple web page using Flask, just for practice and i have this little problem.
i want to count how many times i’ve reloaded page. for example:
count = 0
@app.route("/")
def home():
print(count)
count += 1
return "testing"
but this doesn’t work. if you guys know anything about it please help. <3 Thanks!
>Solution :
the above code will work, but since you are trying to access the count variable from a function, you need to declare in the function that its a global:
count = 0
@app.route("/")
def home():
global count
print(count)
count += 1
return "testing"
more info on global variables here