ImportError: cannot import name 'db' from [package_name] [duplicate]
It looks like you are importing db
(in API/db_model.py
) before it's initialized. The quick and dirty solution might be to import api
after you initialize the db
object in the top level __init__.py
.
from flask import Flaskfrom FlaskUserAuthentication.Site.routes import sitefrom flask_sqlalchemy import SQLAlchemyapp = Flask(__name__)db = SQLAlchemy(app)app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///database.db'from FlaskUserAuthentication.API.routes import api
I suggest you use the app factory pattern, however, as your application grows in complexity.