Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

Flask app stack

View gist:3856206
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.