In general, I like to structure my application in such a way that you do not need an import app in any of the files. For my current project, the only file that the application imports is a file called manage.py , which does a little more than allows me to do certain things using Flask-Script.
A good feature that many Flask extensions have is the init_app method. This allows you to instantiate applications without requiring an application.
Say you created a database called db in a file called db.py It might look something like this:
from flask.ext.sqlalchemy import SQLAlchemy db = SQLAlchemy()
Let's say you configured the application in __init__.py . This file might look something like
from flask import Flask from app.db import db app = Flask(__name__) db.init_app(app)
Now your database is initialized for your Flask application, and you will not have problems with a circular reference when you import db directly through from app.db import db , for example, in models.py .
For my views, I often return to drawings instead of using @app.route('/') methods. As in the database, drawings can simply be imported into your __init__.py file and registered in the application there.
source share