Last active
August 29, 2015 13:59
-
-
Save KyleJamesWalker/10559986 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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