Title: How to create a progress bar using flask?
Tags: python;flask;progress-bar
Question: Just want to insert a progress bar in my html page. It should load from a for in my app.py. That's what I did so far...

app.py

```from flask import Flask, render_template
app = Flask(__name__)

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

@app.route('/progress')
def ajax_index():

   for i in range(500):
      print("%d" % i)
      # I want to load this in a progress bar

if __name__ == "__main__":
    app.run(debug=True)
```

I'm using a bootstrap progress-bar from w3schools in my code

index.html

```<html&gt;
    <head&gt;
       <meta name="viewport" content="width=device-width, initial-scale=1"&gt;
       <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css"&gt;
       <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"&gt;</script&gt;
       <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"&gt;</script&gt;
       <script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"&gt;</script&gt;

       <script&gt;
            $(function () { 
                $("#content").load("/progress"); 
            });
       </script&gt;

    </head&gt;
    <body&gt;
        <div class="container"&gt;
           <h2&gt;Progress Bar With Label</h2&gt;
           <div class="progress"&gt;
              <div class="progress-bar" role="progressbar" aria-valuenow="70" aria-valuemin="0" aria-valuemax="100" style="width:0%"&gt;</div&gt;
           </div&gt;
        </div&gt;
    </body&gt;
</html&gt;
```

Any help, please?

Comment: You need to actually do something that takes time in a separate process or background thread and have it store the progress of the task somewhere so that `/progress` can fetch it. What are you showing the progress of?

Here is the accepted answer: this is pretty simple: poll your api and update the progress bar width and valuenow until finished:

```var interval = setInterval(update_progress, 1000);
function update_progress() {
     $.get('/progress').done(function(n){
         n = n / 5;  // percent value
         if (n == 100) {
            clearInterval(interval);
            callback(); // user defined
         }
         $('.progress-bar').animate({'width': n +'%'}).attr('aria-valuenow', n);    
     }).fail(function() {
         clearInterval(interval);
         displayerror(); // user defined
     });
}
```

Comment for this answer: Could you maybe provide a working example? I am facing the same problem but I am not able to implement this solution since I am fairly new to jquery and flask


{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 1, 'CommentCount': 1, 'ContentLicense': 'CC BY-SA 3.0', 'CreationDate': '2016:00:05/30/16', 'FavoriteCount': 2.0, 'PostTypeId': 1, 'Tags': '<python><flask><progress-bar>', 'Title': 'How to create a progress bar using flask?', 'ViewCount': 14069, 'id': 37531829, 'user_AboutMe': None, 'user_AccountId': 4406377.0, 'user_DisplayName': 'Renzo Rodrigues', 'user_Reputation': 515.0, 'user_Views': 40.0, 'user_id': 3590662.0}}