I\'m new in bluprint, and have problem with importing db into mydatabase.py file which is models file.
I\'ve faced with this error:
ImportErro
This is actually a simple, yet frustrating issue. The problem is you are importing main BEFORE
you are creating the instance of db
in your __init__.py
If move the import to after your db = SQLAlchemy(app)
, it will work:
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql+pymysql://uername:password@localhost/test'
db = SQLAlchemy(app)
from bookshelf.main.controllers import main #<--move this here
app.register_blueprint(main, url_prefix='/')