How to stop Flask method from executing after hitting Page Reload

Viewed 45

I have a basic HTML Form with file input that accepts multiple files. When the user clicks on Upload button I want to print numbers till 10**9 on my terminal.Say while execution of loop the user clicks refresh/reload, I want to stop current loop and redirect to index page. But even after hitting refresh the loop continues to execute.

index.html

<form method="POST" action="upload" enctype="multipart/form-data" class="uploader">        
       <input id="file-upload" type="file" name="fileUpload" accept=".ent,.pdb" multiple/>
       <input type="submit" class="btn btn-primary" value="Upload"/>            
</form>

app.py

from flask import Flask, render_template, redirect

UPLOAD_FOLDER = 'uploads'

app = Flask(__name__)
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER 

@app.route("/")
def index():
        return render_template("index.html")

@app.route('/upload',methods = ['GET','POST'])
def upload_file():

    t=0
    while(t<10**9):
        print(t)
        t+=1
    return redirect('/')

if __name__ == '__main__':
    app.run(debug=True)
0 Answers
Related