Python-API-Development-Fundamentals
Python-API-Development-Fundamentals copied to clipboard
Exercise 21. You must use an application context
In the Exercise 21: Applying Database Insertion, if you will use just a Python console in PyCharm you will catch an exception: RuntimeError: No application found. Either work inside a view function or push an application context. See http://flask-sqlalchemy.pocoo.org/contexts/.
The easiest way to avoid this is to use not just the Python console, but flask shell . Just type in the PyCharm terminal - flask shell, it works in the application context.
you can also put app.app_context().push()
after you create the app app = create_app()
This also avoids the RuntimeError
Why does this work?
you can also put app.app_context().push()
after you create the app app = create_app()
This also avoids the RuntimeError