烧瓶/瓶子项目组织

发布于 2024-10-24 18:39:47 字数 226 浏览 2 评论 0原文

我一直在研究 Python 的微框架,并发现了两个有趣的选择:Flask 和 Bottle。每个都有一些相似的功能。我注意到的一件事是,所有示例站点都显示位于单个 Python 文件内的所有应用程序代码。显然,即使对于中等规模的站点,这也会变得难以快速管理。这些框架中的一个(或两个)是否支持在不同文件之间进行分解,如果是的话,将如何实现?

我熟悉 Django,喜欢它的结构化程度,但我宁愿使用更轻量级但仍然强大的东西。

I've been looking into microframeworks for Python, and have come across two interesting options, Flask and Bottle. each have some similar features. One thing I noticed is that all the example sites show all the application code located inside a single Python file. Obviously, for even moderately sized sites, this would become difficult to manage quite quickly. Do either (or both) of these frameworks support being broken up among different files, and if so how would that be accomplished?

I'm familiar with Django, and like how its a little more structured, but i would rather use something more lightweight, but still powerful.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

予囚 2024-10-31 18:39:47

我对 Bottle 没有任何经验,但请查看 Flask 文档在更大的应用程序上。我的 Flask 应用程序都使用多个 Flask Module 对象正如该页面所建议的,每个 Python 模块一个,它似乎工作得很好。

Module 对象的优点之一是,您可以自定义每个对象的分派,以在应用中创建 URL 路由“域”。例如,我试图在我的一些代码中模仿 Windows 应用程序,所以我有一个 CaseInsensitiveModule 来执行不区分大小写的调度,并且我安装了一个 RemoteModule使用 Flask/Werkzeug 路由系统将 HTTP 请求转换为 Python 方法。

(请注意,在当前的 Flask 版本中,模块现在是蓝图。)

I don't have any experience with Bottle, but take a look at the Flask docs on larger applications. My Flask apps all use multiple Flask Module objects as that page recommends, one per Python module, and it seems to work just fine.

One thing that's nice about the Module objects is that you can customize dispatch on each one to create URL routing "domains" in your app. So for example, I'm trying to ape a Windows app in some of my code so I have a CaseInsensitiveModule that does case-insensitive dispatch, and I rigged up a RemoteModule to turn HTTP requests into Python methods using the Flask/Werkzeug routing system.

(Note that in current Flask versions, Modules are now Blueprints.)

女中豪杰 2024-10-31 18:39:47

我看不出有什么办法可以阻止这个工作。 Flask 和 Bottle 和 Django 一样,都是底层的 Python,而 Python 允许你将文件分解成模块。只要您将相关函数导入到主脚本中,它们就会像在主脚本中定义的一样工作。

I can't see how there could be any way of stopping this from working. Flask and Bottle, like Django, are just Python underneath, and Python allows you to break up files into modules. As long as you importing the relevant functions into the main script, they will just work exactly as if they were defined there.

终陌 2024-10-31 18:39:47

我知道有些人已经开始使用我自己的文章来使用 Flask 执行此操作,尽管根据项目的大小显然还有其他方法可以执行此操作;即使我为较小的项目删除了基于文件的目录类型模块。看看 http ://www.cols-code-snippets.co.uk/2011/02/my-take-on-flask-application-sculpture.html

I know a few people have started using my own article on doing this with Flask, although there are obviously other ways to do it depending on the size of the project; even I drop the directory type module for a file based one for smaller projects. Have a look at http://www.cols-code-snippets.co.uk/2011/02/my-take-on-flask-application-skeleton.html

表情可笑 2024-10-31 18:39:47

我最近发布了一篇关于如何在 Google App Engine 中开始使用 Bottle+Jinja2 的教程。我这里的重点是如何组织项目文件。您也许可以获得可以使用的东西: http://codeaspoetry.wordpress.com/2011/11/27/how-to-build-a-web-app-using-bottle-with-jinja2-in-google-app-engine/

I recently posted a sort of tutorial on how to get started with Bottle+Jinja2 in Google App Engine. My emphasis here is on how to organize the project files. You may be able to get something that you can use: http://codeaspoetry.wordpress.com/2011/11/27/how-to-build-a-web-app-using-bottle-with-jinja2-in-google-app-engine/

满意归宿 2024-10-31 18:39:47

这实际上取决于您想要实现的目标,对于微服务/应用程序/网站来说,瓶子非常简单且重量轻。如果您计划您的应用程序届时会增长,那么 Flask 可能是您的不错选择,因为它有很多扩展。我们有大约 40 到 50 个用瓶子编写的微服务,从未遇到过任何问题。

It really depends what you are trying to achieve, for micro service/applications/websites bottle is very straight forward and light weight. If you plan your application to grow by the time then Flask might be good option for you coz it has lot of extensions. We have about 40 to 50 micro services written in bottle and never faced any issues.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文