我刚刚创建了一个烧瓶应用程序,到目前为止,我的Hello world!有一个路由器。模板。
我想添加一些(很多)更多的功能,但我不知道应该如何构建应用程序目录。
构建Flask应用程序的最常用方法是什么? 例如,我应该为我所有的路由创建一个 routes.py 吗? SQLAlchemy的东西去哪了? 模型应该在 models.py ?
解决方案您应该查看Flask文档的Patterns部分中的Larger Applications页面: http:// flask .pocoo /文档/模式/封装/ 。这似乎是大多数人在他们的应用程序调用一个包而不是一个模块时所遵循的模型。
我相信 views.py
code>就是你要的 routes.py 。之后,模型将进入 models.py ,表单将进入 forms.py 等。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.
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?
解决方案You should check out the Larger Applications page in the Patterns section of the Flask docs: flask.pocoo/docs/patterns/packages/. It seems to be the model that most people follow when their application calls for a package instead of a module.
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应用程序中的常用文件夹/文件结构
发布评论