Flask应用程序中的常用文件夹/文件结构 [英] Common folder/file structure in Flask app

查看:275
本文介绍了Flask应用程序中的常用文件夹/文件结构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚创建了一个烧瓶应用程序,到目前为止,我的Hello world!有一个路由器。模板。

我想添加一些(很多)更多的功能,但我不知道应该如何构建应用程序目录。



构建Flask应用程序的最常用方法是什么?
例如,我应该为我所有的路由创建一个 routes.py 吗?
SQLAlchemy的东西去哪了?
模型应该在 models.py

解决方案

您应该查看Flask文档的Patterns部分中的Larger Applications页面: http:// flask .pocoo.org /文档/模式/封装/ 。这似乎是大多数人在他们的应用程序调用一个包而不是一个模块时所遵循的模型。



我相信 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: 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.

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆