Flask应用程序中的常用文件夹/文件结构

编程入门 行业动态 更新时间:2024-10-28 01:19:10
本文介绍了Flask应用程序中的常用文件夹/文件结构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我刚刚创建了一个烧瓶应用程序,到目前为止,我的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应用程序中的常用文件夹/文件结构

本文发布于:2023-11-12 17:06:31,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1582051.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:应用程序   文件夹   常用   结构   文件

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!