Skip to content
Advertisement

Flask – RuntimeError: Working outside of application context

I am receiving the ‘RuntimeError: Working outside of application context.’ error in my flask application and am struggling to understand why. I have tried to push the app context, however that didn’t seem to work for me and I may just be slightly confused as to how to access the ‘current_app’ so I can write to my logger from other classes and blueprints. My code is as follows:

run.py:

JavaScript

init.py:

JavaScript

bp_bundle.py (blueprint):

JavaScript

stack trace:

JavaScript

Advertisement

Answer

When you import the module here from caffeine.routes.bp_bundle import bundle the global statements at outermost sections will be executed. Now at this time the app is not running and this module is trying to use current_app. Put this inside a route of Flask and it will work.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement