Flask requires application context be available when accessing certain items, such as the
g construct. Many of these accessors are simply a proxy for the current version, which is bound to the
Flask application context.
For example, if you’ve got a command line app, you simply need to instantiate your app and push a context:
from flask import Flask, current_app app = Flask(__name__) with app.app_context(): # within this block, current_app points to app. print current_app.name