我想在REPL中对Flask' jsonify
的行为进行一些实验。但似乎我无法在应用程序上下文之外调用它。有没有简单的方法来建立一个可接受的环境?
~ $ python
Python 2.7.11 (default, Dec 7 2015, 21:16:24)
[GCC 4.8.4] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from flask import jsonify
>>> jsonify([1,2,3])
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/app/.heroku/python/lib/python2.7/site-packages/flask/json.py", line 234, in jsonify
if current_app.config['JSONIFY_PRETTYPRINT_REGULAR'] \
File "/app/.heroku/python/lib/python2.7/site-packages/werkzeug/local.py", line 343, in __getattr__
return getattr(self._get_current_object(), name)
File "/app/.heroku/python/lib/python2.7/site-packages/werkzeug/local.py", line 302, in _get_current_object
return self.__local()
File "/app/.heroku/python/lib/python2.7/site-packages/flask/globals.py", line 34, in _find_app
raise RuntimeError('working outside of application context')
RuntimeError: working outside of application context