0Pricing
Flask Academy · Lesson

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

  1. App Context vs Request Context
  2. current_app and the g Object
  3. Context Locals and Thread Safety
  4. Push a Context in Scripts and Shells
← Back to Flask Academy