These Flask notes were taken while building a companion blog project, so the code snippets and
examples are relative to that project (referred to below as flasky/shadys-blog).
If you try to perform a database operation or any operation on the python terminal in your flask application and you get an app context error, you can use the below code to fix it.
from flasky import appfrom flasky.models import Postfrom flask import current_app
# Get the application contextctx = app.app_context()ctx.push()
# Access the current applicationcurrent_app.app_context().push()
# Perform your database operationsposts = Post.query.all() #just an example# Rest of your code
# Clean up the application contextctx.pop()