Rectangle 27 0

python How to share the global app object in flask?


from .main import app
from flask import Flask
app = Flask(__name__)

# do some stuff with app
from .views import view1, view2
from .server import run
from flask import Flask
from view import tags

app = Flask(__name__)
from mypackagename.main import app

And then in other files, you could do:

Just import it from your other files. Perhaps the best way to do this is to put your app object in one single file and have everything else import from it.

One thing to be careful of is circular imports. The easiest way to handle this issue is to create your app first and then import whatever else you need to from your base file after you create it.

So long as you put the imports after you've created app, like the above, you shouldn't have an issue with circular imports.

or, if outside your package, just use the complete string

Note