One of the common mistakes using Flask is circular import.
To avoid it, we can split one application file into three files:
application.pyfile includes all the initiations and setup
www.pyfile includes all the routes and blueprint registrations
manager.pyfile starts the server
from flask import Flask from flask_sqlalchemy import SQLAlchemy app = Flask(__name__) app.config["SQLALCHEMY_DATABASE_URI"] = "mysql://root:firstname.lastname@example.org/mysql" db = SQLAlchemy(app)
from application import app from indexController import index_page app.register_blueprint(index_page, url_prefix="/user")
from application import app if __name__ == '__main__': app.run(host="0.0.0.0", debug=True)