在类属性读 flask 的配置报错
from flask import current_app
class Foo(object):
URL = current_app.config['EX_URL']
...
File "/path/to/example.py", line 20, in Foo
URL = current_app.config['EX_URL']
File "/path/to/miniconda/envs/example/lib/python3.8/site-packages/werkzeug/local.py", line 347, in __getattr__
return getattr(self._get_current_object(), name)
File "/path/to/miniconda/envs/example/lib/python3.8/site-packages/werkzeug/local.py", line 306, in _get_current_object
return self.__local()
File "/path/to/miniconda/envs/example/lib/python3.8/site-packages/flask/globals.py", line 52, in _find_app
raise RuntimeError(_app_ctx_err_msg)
RuntimeError: Working outside of application context.
This typically means that you attempted to use functionality that needed
to interface with the current application object in some way. To solve
this, set up an application context with app.app_context(). See the
documentation for more information.
提示是让执行 app.app_context()
, 我尝试导入 from start import app
后执行, 又报了循环导入的问题, 想请教这个该怎么解决
这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。
V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。
V2EX is a community of developers, designers and creative people.