我正在尝试解决Flask中的循环导入问题,但是,我正在努力理解这一点,因为我相信我使用与documentation中相同的结构并且使用相同的结构导入模式,如Flask Mega Tutorial。
我的结构看起来很相似:
root/
run.py
config.py
app/
__init__.py
views.py
models.py
env/
app/__init__.py
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from config import *
app = Flask(__ name __)
app.config.from_object('config')
db = SQLAlchemy(app)
from app import views, models
(导入视图,模型语句是__init__.py
)
app/views.py
from app import app, db
from models import Entry, Category
from config import *
app/models.py
from app import db
错误追溯:
Traceback (most recent call last):
File "./run.py", line 2, in <module>
from app import app
File "/Users/paulmclear/Coding/projects/prodblog/app/__init__.py", line 44, in <module>
from app import views, models
ImportError: cannot import name views
任何人都可以建议我做错了吗?非常感谢提前。