我正在尝试清理我的烧瓶应用程序,因此决定使用样板结构。我有auth_bp
蓝图,它在auth.py中定义,我具有以下文件夹结构;
-app_root
-application
-__init__.py
- auth.py
- other files like template and static
- config.py (for configuration)
- server.py (to run the app through flask_script )
在__init__.py
中,我有两个类:app
和mail
,需要在我的auth.py
文件中使用它们。
但是当我写的时候:
from application import app, mail
我得到一个ImportError: cannot import name app
这是__init__.py
中的代码:
from flask import Flask
from flask_mail import Mail
import config
from auth import auth_bp
app = Flask(__name__)
app.config.from_object("config.Config")
mail = Mail(app)
app.register_blueprint(auth_bp)
@app.route("/")
def home():
return "homepage"
编辑:已解决:创建应用和邮件对象后,我必须导入auth。