webapp\__init__.py
:
from flask import Flask
from webapp import views
app = Flask(__name__)
webapp\views.py
:
from webapp import app
@app.route('/'):
return 'Hello World!'
set FLASK_APP=webapp
后,初始化首先执行__init__.py
中的from webapp import views
语句views.py
,执行from webapp import app
,需要从webapp
中导入app
,而此时app
对象还未创建flask.cli.NoAppException: Could not import app
webapp\__init__.py
:
from flask import Flask
app = Flask(__name__)
from webapp import views