我认为这不是循环依赖的进口问题。
这就是我的文件层次结构
run.py 的代码是
from site import app
if __name__ == "__main__":
app.run()
__ init.py __
from flask import Flask
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
app = Flask(__name__)
app.config['SECRET_KEY'] = '84e0621dd931baa7e6a014901c6183d5'
#sqllite is for development purposes
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///site.db'
db = SQLAlchemy(app)
from site import routes
routes.py
的开头from flask import render_template, url_for, flash, redirect
from site import app
from site.forms import RegistrationForm, LoginForm
from site.models import User, Campaign
我在bash shell中运行的命令是
python3 run.py
我得到的是
Traceback (most recent call last):
File "run.py", line 1, in <module>
from site import app
ImportError: cannot import name 'app' from 'site' (/usr/local/Cellar/python/3.7.3/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site.py)
答案 0 :(得分:0)
已经存在一个名为site的模块,因此我不得不更改文件夹/模块的名称。