想象一个使用蓝图模式实现的简单 Flask 项目。
app
+-blueprint_1
| +-__init__.py
| +-views.py
|
+-utils.py
现在,假设我想使用此处的最佳实践在我的 blueprint_1
View 中导入 utils
:http://docs.python-guide.org/en/latest/writing/structure/#modules
即,我想简单地执行 import foo
而不是 from foo import too_lazy, to_type, chunk_of, names
如何在蓝图中进行这种类型的导入?
最佳答案
这可能不是正确的方式,这意味着 from
是善意的:
#blueprint_1/views.py
...
try:
import os
os.chdir('..')
import utils
except:
pass
关于python - 如何从蓝图中导入包?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41398695/