Push a Context in Scripts and Shells
Run code outside a request with app_context.
Outside the Web
Sometimes you run Flask code with no request, like a script that seeds the database. There is no context, so the usual proxies fail.
The Telltale Error
Run such code and Flask raises RuntimeError: working outside of application context. It is telling you no app context is active.
All lessons in this course
- App Context vs Request Context
- current_app and the g Object
- Context Locals and Thread Safety
- Push a Context in Scripts and Shells