Created
October 6, 2019 06:36
-
-
Save senaps/b168c5b1de7e54bc3854a6245103e4db to your computer and use it in GitHub Desktop.
flask context
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
@contextmanager | |
def get_app_context(conf=None): | |
"""get an app context! | |
we will receive the name of the application and then try to build out the | |
applicaton and return it. the important thing with this function is that we | |
will return the application context not the actual application object. | |
this is usefull for modules and functions that need the application context | |
to be able to do what they would need to do. | |
the config is the name of the config class we want to use to create the app | |
with. | |
:param conf: name of the config class | |
:return: a flask application context | |
""" | |
if not conf: | |
conf = 'development' | |
try: | |
app = create_app(cm.get(conf)) | |
with app.app_context() as ctx: | |
yield ctx | |
finally: | |
pass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment