为什么我不能导入__init__.py中声明的类?

时间:2018-07-26 19:55:16

标签: python flask python-import

我正在尝试清理我的烧瓶应用程序,因此决定使用样板结构。我有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中,我有两个类:appmail,需要在我的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。

0 个答案:

没有答案