首页 > flask使用blueprint时的文件结构

flask使用blueprint时的文件结构

初学flask,在使用blueprint时遇到了问题。 项目文件结构如下:

project
...run.py
...apps
......__init__.py
......admin
.........__init__.py
.........views.py
.........models.py
......frontend
.........__init__.py
.........views.py
.........models.py

adminfrontend是两个blueprint

请问这样的结构是否合理,如果合理在哪写

app=Flask(__name__)
db=SQLAlchemy()

不知道是不是循环引用的问题,报ImportError: cannot import name ***的错误。


是循环引用的问题 我的代码结构跟你的一样 也出现了同样的问题 感觉一楼的解决方法也不是很干净 不过确实是个解决方案


或许你可以参考下我的项目结构,虽然不是那么专业

app在me_0418.py里边定义

Blueprint在controllers的子包的__init__.py中定义

地址

【热门文章】
【热门文章】