Installing flask extension: ext = Ext(app) versus Ext(app)
<p>I'm learning flask web development by following a tutorial. Currently, the first few lines of my app is:</p>

<pre><code>from flask import Flask, render_template
from flask_bootstrap import Bootstrap

app = Flask(__name__)

bootstrap = Bootstrap(app)
</code></pre>

<p>However, when I change <code>bootstrap = Bootstrap(app)</code> to <code>Bootstrap(app)</code>, nothing breaks. So what's the purpose of storing the <code>Bootstrap</code> instance in a variable, which is not used in the rest of code?</p>

<p>With your current code, it's true there is no need to keep the instance into a variable, </p>

<p>But in practice, you would create the Bootstrap instance without passing the <code>app</code> instance, then on some initialization method, you would call the <code>init_app</code> method of the Bootstrap instance to initialize it with <code>app</code>, like so:</p>

<pre><code>bootstrap = Bootstrap()

def create_app(config_name):
    app = Flask(__name__)
    app.config.from_object(config[config_name])

    bootstrap.init_app(app)

    return app 
</code></pre>

<p>This will also include all other instances of other tools, like Flask-SQLALchemy, Moment, Mail...etc</p>

python flask flask-extensions