Flask 应用程序中的常用文件夹/文件结构 [英] Common folder/file structure in Flask app
问题描述
我刚刚创建了一个 Flask 应用程序,到目前为止我有一个用于Hello world!"的路由器.模板.
I have just created a flask application and so far I have a router for my "Hello world!" template.
我想添加一点(很多)更多的功能,但我想知道我应该如何构建应用程序目录.
I would like to add a little (a lot) more functionality, but I wonder how I should structure the app directory.
构建 Flask 应用程序的最常见方式是什么?例如,我应该为我的所有路线创建一个 routes.py
吗?SQLAlchemy 的东西去哪里了?模型应该在 models.py
中吗?
What's the most common way of structuring a Flask app?
For instance, should I create a routes.py
for all my routes?
Where does the SQLAlchemy stuff go?
Should models be in models.py
?
推荐答案
您应该查看 Flask 文档模式部分中的大型应用程序页面:http://flask.pocoo.org/docs/patterns/packages/.当他们的应用程序调用包而不是模块时,这似乎是大多数人遵循的模型.
You should check out the Larger Applications page in the Patterns section of the Flask docs: http://flask.pocoo.org/docs/patterns/packages/. It seems to be the model that most people follow when their application calls for a package instead of a module.
我相信 views.py
就是您所说的 routes.py
.之后,模型将进入models.py
,表单将进入forms.py
,等等.
I believe views.py
is what you are calling routes.py
. After that, models would go in models.py
, forms would go in forms.py
, etc.
这篇关于Flask 应用程序中的常用文件夹/文件结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!