0

Trying to add flask-Ask to an existing flask website that uses the runserver pattern where app setup done in init but app.run is called in runserver

/myapp
    /myapp
    __init__.py
     views.py
     alexa_views.py
runserver.py

This pattern works fine for Flask ( its recommended for larger apps) but Flask-Ask is failing silently when app.run(debug=True) is called from runserver.py. If I call app.run(debug=True) in _init__.py and run that then Flask-Ask works fine and Alexa responds. Any ideas?

code:

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')

init.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)
Bill
  • 618
  • 6
  • 15

1 Answers1

0

I am going to close this. The problem does exist in my real app but this simple example now works fine so I will have to dig deeper to find something I can demonstrate.

Bill

Bill
  • 618
  • 6
  • 15
  • Whatever the issue, it might be worth fixing that "# late import of views to break circular import", perhaps by adding your views onto another blueprint and importing that – farridav Mar 05 '18 at 13:51
  • Thanks - I did figure it out. Once I turned on Flask debug logging I saw bad CSRF token next to the 400 return and found out that by default CSRF is enabled for all routes including REST. Fix was to exempt flask-ask routes – Bill Mar 06 '18 at 15:42