烧瓶导入模块有问题吗?

时间:2019-07-13 09:18:35

标签: python

运行项目后,运行python run.py将不会报告 ImportError:无法从“ app”中导入名称“ app”,但是在忘记停止重新启动项目后报告了错误

Modify the file name and import it again

    app/__init__.py
    import os
    from flask import Flask
    from flask_sqlalchemy import SQLAlchemy
    from flask_login import LoginManager
    from flask_openid import OpenID
    from config import basedir
    from app import views,models

    app = Flask(__name__)
    app.config.from_object('config')
    db = SQLAlchemy(app)

    lm = LoginManager()
    lm.init_app(app)
    oid = OpenID(app, os.path.join(basedir,'tmp'))

app/views.py
    from app import app,db,lm,oid

run.py
   from app import app
   app.run(debug = True)

错误

Traceback (most recent call last):
File "run.py", line 2, in <module>
  from app import app
  File "D:\code\python\flask\microblog\app\__init__.py", line 7, in <module>
from app import views,models
     File "D:\code\python\flask\microblog\app\views.py", line 3, in <module>
       from app import app,db,lm,oid
   ImportError: cannot import name 'app' from 'app' (D:\code\python\flask\microblog\app\__init__.py)

0 个答案:

没有答案