public
Last active

Flask app stack

  • Download Gist
gistfile1.py
Python
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
from flask import Flask
from flask import _app_ctx_stack as stack
 
myapp = Flask(__name__)
 
def do_something():
ctx = stack.top
if ctx is None:
print "ctx is None"
else:
print "ctx is not None"
 
# Not during a request
do_something()
 
# During a request
# See http://flask.pocoo.org/docs/testing/
with myapp.test_request_context('/nowhere'):
do_something()
 
 
=======
Output
=======
ctx is None
ctx is not None

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.