Skip to content

Instantly share code, notes, and snippets.

@KyleJamesWalker
Last active August 29, 2015 13:59
Show Gist options
  • Save KyleJamesWalker/10559986 to your computer and use it in GitHub Desktop.
Save KyleJamesWalker/10559986 to your computer and use it in GitHub Desktop.
from flask import Blueprint
shared_value = None
class RegisteringExampleBlueprint(Blueprint):
'''
Example showing how to access a value for routes
saved in flask's configuration section for all routes in
blueprint.
Note if you tried simply saying api = app.config['value']
you would get a context error.
'''
def register(self, app, options, first_registration=False):
global shared_value
shared_value = app.config['value']
super(RegisteringExampleBlueprint,
self).register(app, options, first_registration)
the_blueprint = RegisteringExampleBlueprint('example', __name__)
### Alternate with standard Blueprint ###
@the_blueprint.record
def record_example(setup_state):
global shared_value
app = setup_state.app
shared_value = app.config['value']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment