Flask: How to use app context inside blueprints?
In your app - when registering the blueprint - you need to push the context manually.
Refer to the snippet below and notice how the call-out to the init_db function is wrapped with the application context - the with ensures that the context is destroyed upon completion of your task.
def create_app():
app = Flask(__name__)
with app.app_context():
init_db()
return app
Source
From the docs about appcontext:
The application context is what powers the current_app context local
Applied to your example:
from flask import Blueprint, current_app
sample = Blueprint('sample', __name__)
@sample.route('/')
def index():
x = current_app.config['SOMETHING']
For reference here is a small gist I put together, as mentioned in the comments.