尝试添加flask-Ask到使用runserver模式的现有烧瓶网站,其中app setup在 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
runserver.py
# running this starts website normally but Flask-Ask does nothing
from myapp import app
if __name__ == '__main__':
app.run(debug=True)
答案 0 :(得分:0)
我要关闭这个。 问题确实存在于我的真实应用程序中,但这个简单的例子现在工作正常,所以我将不得不深入挖掘,找到我可以展示的东西。
比尔