也许您需要在应用程序上下文中调用您的函数:
with app.app_context(): # call your method here
Juan Pablo S.. 14
来自Flask的源代码flask/globals.py
:
_app_ctx_err_msg = '''\ Working outside of application context. This typically means that you attempted to use functionality that needed to interface with the current application object in a way. To solve this set up an application context with app.app_context(). See the documentation for more information.\ '''
在文档之后,您可以看到您需要flask.current_app
指出您的应用程序,而目前却没有.
在Flask初始化之前,您可能正在调用数据库函数.我的猜测是你的app
对象还没有用Flask
构造函数创建.
也许您需要在应用程序上下文中调用您的函数:
with app.app_context(): # call your method here
来自Flask的源代码flask/globals.py
:
_app_ctx_err_msg = '''\ Working outside of application context. This typically means that you attempted to use functionality that needed to interface with the current application object in a way. To solve this set up an application context with app.app_context(). See the documentation for more information.\ '''
在文档之后,您可以看到您需要flask.current_app
指出您的应用程序,而目前却没有.
在Flask初始化之前,您可能正在调用数据库函数.我的猜测是你的app
对象还没有用Flask
构造函数创建.