Python-API-Development-Fundamentals icon indicating copy to clipboard operation
Python-API-Development-Fundamentals copied to clipboard

Exercise 21. You must use an application context

Open kirillmasanov opened this issue 5 years ago • 2 comments

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.

kirillmasanov avatar Aug 19 '20 21:08 kirillmasanov

you can also put app.app_context().push()

after you create the app app = create_app()

This also avoids the RuntimeError

SinclairPythonAkoto avatar Nov 17 '21 15:11 SinclairPythonAkoto

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

kingtroga avatar Jul 30 '22 18:07 kingtroga