尝试将 flask-Ask 添加到使用 runserver 模式的现有烧瓶网站,其中应用程序设置在init中完成,但 app.run 在 runserver 中调用
/myapp
/myapp
__init__.py
views.py
alexa_views.py
runserver.py
这种模式适用于 Flask(它推荐用于较大的应用程序),但是当从 runserver.py 调用 app.run(debug=True) 时,Flask-Ask 会静默失败。如果我在 _init__.py 中调用 app.run(debug=True) 并运行它,那么 Flask-Ask 工作正常并且 Alexa 响应。有任何想法吗?
代码:
alexa_views.py
from flask import blueprints
from flask_ask import Ask, statement
askblueprint = blueprints.Blueprint('alexa', __name__, url_prefix='/alexa')
ask = Ask(blueprint=askblueprint)
@ask.launch
def launch():
return statement (' it works')
初始化.py
from flask import Flask, blueprints
from myapp.alexa_views import askblueprint
app = Flask(__name__)
app.register_blueprint(askblueprint)
# lots of other unrelated configuration here - db etc
# running app here causes Flask-Ask to work!
# if __name__ == '__main__':
# app.run(debug=True)
# late import of views to break circular import
import myapp.views
运行服务器.py
# running this starts website normally but Flask-Ask does nothing
from myapp import app
if __name__ == '__main__':
app.run(debug=True)