什么是好的轻量级Python MVC框架?

时间:2021-06-27 11:28:01

I know there are a ton of Python frameworks out there. Can you guys point me in the right direction? My primary concern is simplicity, I don't need a lot of extraneous features. Here are a couple of other things that I'd want (or don't want):

我知道有很多Python框架。你们能给我指出正确的方向吗?我最关心的是简单性,我不需要很多无关的特性。以下是一些我想要(或不想要)的东西:

  • don't care for ORM, just want it to work with MySQL
  • 不关心ORM,只想让它和MySQL一起工作
  • has configurable routes
  • 有可配置的路由
  • has support for layouts
  • 支持布局

19 个解决方案

#1


44  

web2py is 265Kbytes of source code and 1.2MB all inclusive (compare with 4.6MB of Django). Yet web2py will do everything you need (manage session, cookies, request, response, cache, internationalization, errors/tickets, database abstraction for GAE, SQLite, MSSQL, MySQL, Postgres, Oracle, FireBird, etc.) It does not need installation - just unzip and click on it - and you can do development in your browser.

web2py是源代码的265Kbytes,包含1.2MB(与Django的4.6MB相比)。然而web2py会做你所需要的一切(管理会话、cookie、请求、响应、缓存、国际化、错误/票据、GAE的数据库抽象、SQLite、MSSQL、MySQL、Postgres、Oracle、FireBird等等),它不需要安装——只需解压并点击它——你可以在浏览器中进行开发。

Web2py has both routes and reverse routes.

Web2py具有路由和反向路由。

Web2py has a hierarchical template systems which means a view can extend a layout which can extend another layout, etc. views can also include other views.

Web2py有一个层次化的模板系统,这意味着一个视图可以扩展一个可以扩展另一个布局的布局,等等,视图也可以包含其他视图。

#2


32  

Since you explicitly don't want an ORM, I'd stay away from a "full stack" framework if I were you. Python's WSGI standard gives you a ton of easy-to-use options that will give you just the features you need and even let you choose your style of working.

既然你明确地不想要一个ORM,如果我是你,我就会远离“完整堆栈”框架。Python的WSGI标准为您提供了大量易于使用的选项,这些选项只提供您需要的特性,甚至允许您选择自己的工作风格。

Here's an example: for URL dispatch you can use Routes, which ports over the URL dispatch style of Rails. Or you could combine Selector with WebOb if that style suits you more.

这里有一个例子:对于URL分派,您可以使用路由,该路径通过URL分派样式的Rails。或者你也可以把选择器和WebOb组合在一起如果那个样式更适合你的话。

For "layouts", you can use the powerful Jinja2 if you want templates that cannot run code. Or, Mako if you prefer to be able to mix a little code in with your templates. You can even use Deliverance to control the layout of pages that are composed from multiple apps and even multiple languages!

对于“布局”,如果需要不能运行代码的模板,可以使用功能强大的Jinja2。或者,如果您希望能够在模板中混合一些代码,那么可以使用Mako。您甚至可以使用Deliverance控制由多个应用程序甚至多种语言组成的页面的布局!

A full-stack web framework is nice in that it makes a bunch of choices for you, letting you pay attention just to the app your building. But, the choices I've listed above are a good collection to get you going building your own. If you head down that path, you'll find it easy to plug in Beaker for caching and sessions if you need them, or WebError to help you with debugging.

一个完整的web框架是很好的,因为它为你做了很多选择,让你只关注你的应用程序你的建筑。但是,我上面列出的选择是一个很好的集合,可以让你建立自己的。如果沿着这条路走下去,您会发现,如果需要的话,可以插入Beaker来进行缓存和会话,或者使用WebError来帮助您调试。

Personally, I'm a big fan of ORMs (particularly SQLAlchemy), but if you're looking to go ORM free and lightweight overall you can't beat combining the great WSGI components available in Python.

就我个人而言,我是ORM(特别是SQLAlchemy)的忠实粉丝,但是如果您希望实现ORM免费和轻量级,那么您就不能将Python中可用的WSGI组件组合起来。

#3


11  

Give web.py a try. It's very simple and may provide the minimalism that you are looking for.

给web。py一试。它非常简单,可以提供你正在寻找的极简主义。

#4


9  

Pylons.

塔。

It's much better than django, and doesn't come with a crappy ORM.

《被解救的姜戈》比《被解救的姜戈》要好得多,也没有什么糟糕的情节。

#5


8  

People already gave many answers concerning web application frameworks, but MVC (or any other paradigm) is not tied to web only. That's just for clarity.

人们已经给出了许多关于web应用程序框架的答案,但是MVC(或其他任何范例)并不仅仅局限于web。这只是为了清晰。

If you are about plain MVC, Pylons conforms to paradigm in a stricter way. Django interprets MVC and they call it model-template-view, but the idea of role separation is the same. Actual choice is a matter of personal taste, although none of these two I consider lightweigth (Pylons might seem lighter, but in fact is not, and recently Django gathered some additional weight - most likely you will not fit even small application like personal blog in 20MB resident memory).

如果您使用的是普通的MVC,那么Pylons将以更严格的方式遵循范例。Django解释了MVC,他们称之为model-template-view,但是角色分离的概念是一样的。实际的选择是一个个人喜好的问题,尽管我认为这两个都不是lightweigth (Pylons可能看起来更轻,但实际上不是,最近Django收集了一些额外的重量——最可能的是,在20MB的常驻内存中,你甚至都装不下个人博客这样的小应用程序)。

Of course, nothing will stop you from writing your own framework, eg. with WebOb. You can make it as light as you want (and learn many things trying).

当然,没有什么能阻止你编写自己的框架。WebOb。你可以让它变得像你想要的一样轻(并且学习很多尝试的东西)。

#6


6  

If you want something simple, without having to make your own framework, while still not being all inclusive (django), you might want to try CherryPy. It can use almost any dispatcher (Page Handler / URL routing system). You would also have to pick your own templating engine, Genshi is my favorite.

如果您想要简单的东西,而不需要创建自己的框架,同时又不包含所有内容(django),那么您可能需要尝试CherryPy。它可以使用几乎任何dispatcher(页面处理程序/ URL路由系统)。你也可以选择自己的模板引擎,源氏是我的最爱。

#7


6  

checkout https://github.com/salimane/bottle-mvc or https://github.com/salimane/flask-mvc . They are boilerplates that could get you started with controllers, models in separate folders. They are based on bottle and flask micro frameworks, no useless features, they give you the flexibility to plugin whatever modules you want.

签出https://github.com/salimane/bottle-mvc或https://github.com/salimane/flask-mvc。它们是样板文件,可以让你从控制器开始,在不同的文件夹中建立模型。它们基于bottle和flask微框架,没有无用的特性,它们给你灵活的插入任何你想要的模块。

#8


6  

When it comes to desktop applications Dabo is a good choice. It's a cross platform framework on top of wxPython which supports MySql, Postgresql, Firebird and Sqlite.

对于桌面应用程序,Dabo是一个不错的选择。它是wxPython之上的一个跨平台框架,支持MySql、Postgresql、Firebird和Sqlite。

#9


5  

You want web2py. Check it:

你想要web2py。检查:

  • don't care for ORM, just want it to work with MySQL
  • 不关心ORM,只想让它和MySQL一起工作

Web2py doesn't have a ORM, but it does have a syntactic wrapper over SQL that makes it much easier to do the SQL.

Web2py没有ORM,但是在SQL上有一个语法包装器,这使得执行SQL更加容易。

  • has configurable routes
  • 有可配置的路由
  • has support for layouts
  • 支持布局

...web2py has both of these.

…web2py有这两个。

And web2py is more lightweight than django/rails/whatever on pretty much all counts. It's VERY easy to learn. The hardest things about learning a MVC framework are the scripts, the ORM, and (with django) the template language. But web2py got rid of the scripts, simplified the ORM, and the template language is just python in a rad clever way.

web2py比django/rails/任何东西都轻。这很容易学。学习MVC框架最困难的事情是脚本、ORM和(使用django)模板语言。但是web2py去掉了脚本,简化了ORM,模板语言只是python的一个rad的巧妙方式。

#10


4  

Yes, I would say Django is definitely the way to go. Its modular design ensures that you can mix and match components (ORM, templating engine, URL dispatch, ...) Instead of being stuck with a component the framework provides you, you can replace it with any 3rd party equivalent instead.

是的,我想说,《被解救的姜戈》绝对是一条出路。它的模块化设计确保您可以混合和匹配组件(ORM、模板引擎、URL分派、…)与框架提供的组件不同,您可以使用任何第三方等效组件替换它。

#11


4  

Django!

Django !

Google App Engine uses it.

谷歌App Engine使用它。

I use it too for my own pet projects.

我也用它来做我自己喜欢的项目。

#12


3  

web2py! django calls a controller a view, 'nuf said.

web2py !django将控制器称为视图。

#13


3  

If you want simplicity use web2py or pylons. Django is good...but the learning curve is steep

如果您想要简单,请使用web2py或pylons。Django是好的…但是学习曲线是陡峭的

#14


2  

Django. You don't have to use the additional features, and it's well designed so you can mix-n-match 3rd-party libraries as needed.

Django。您不需要使用其他特性,而且它设计良好,因此您可以根据需要混合使用n-match 3 -party库。

#15


2  

I'm really new on Python but I tried quiet a few, specially Django and web2py. I loved the simplicity of web2py, I was able to create a site of medium complexity in a few days. It has an imprecessive sets of feature a DAL, code generation, HTML hlpers and for me the most important feature was the documentation in the site is quite complete.

我对Python非常陌生,但是我尝试了一些安静的方法,特别是Django和web2py。我喜欢web2py的简单性,我能够在几天内创建一个中等复杂度的站点。它有一个隐性的特性集一个DAL,代码生成,HTML hlpers,对我来说,最重要的特性是网站的文档相当完整。

#16


2  

I would take a look at Pylons; it is lightweight and fast.

我想看看电塔;它是轻量级和快速的。

#17


2  

I'm also on the Django boat. Here are a few reasons why:

我也在Django船上。以下是一些原因:

  • You'll likely save time with Django's admin interface in avoiding manual queries.
  • 使用Django的管理界面可以节省时间,避免手工查询。
  • Django's templating system is fantastic
  • Django的模板系统非常棒
  • Django has a WONDERFUL community, very eager to help (see #django on freenode)
  • Django有一个很棒的社区,非常渴望提供帮助(参见freenode上的# Django)

#18


-1  

Django is my recommendation.

Django是我的建议。

You can find an introduction to it here (a Google Tech Talk by Jacob Kaplan-Moss):

你可以在这里找到它的介绍(Jacob Kaplan-Moss在谷歌Tech上的演讲):

And you may also want to have a look at Adrian Holovaty's talk given at Snakes and Rubies, DePaul University:

你也可以看看Adrian Holovaty在DePaul大学对蛇和红宝石的演讲:

#19


-3  

While not all Python frameworks explicitly support MVC, it is often trivial to create a web site which uses the MVC pattern by separating the data logic (the model) from the user interaction logic (the controller) and the templates (the view).

虽然不是所有的Python框架都显式地支持MVC,但是创建一个使用MVC模式的web站点通常是很琐碎的,它将数据逻辑(模型)与用户交互逻辑(控制器)和模板(视图)分离开来。

http://docs.python.org/howto/webservers.html#model-view-controller

http://docs.python.org/howto/webservers.html模型-视图-控制器

#1


44  

web2py is 265Kbytes of source code and 1.2MB all inclusive (compare with 4.6MB of Django). Yet web2py will do everything you need (manage session, cookies, request, response, cache, internationalization, errors/tickets, database abstraction for GAE, SQLite, MSSQL, MySQL, Postgres, Oracle, FireBird, etc.) It does not need installation - just unzip and click on it - and you can do development in your browser.

web2py是源代码的265Kbytes,包含1.2MB(与Django的4.6MB相比)。然而web2py会做你所需要的一切(管理会话、cookie、请求、响应、缓存、国际化、错误/票据、GAE的数据库抽象、SQLite、MSSQL、MySQL、Postgres、Oracle、FireBird等等),它不需要安装——只需解压并点击它——你可以在浏览器中进行开发。

Web2py has both routes and reverse routes.

Web2py具有路由和反向路由。

Web2py has a hierarchical template systems which means a view can extend a layout which can extend another layout, etc. views can also include other views.

Web2py有一个层次化的模板系统,这意味着一个视图可以扩展一个可以扩展另一个布局的布局,等等,视图也可以包含其他视图。

#2


32  

Since you explicitly don't want an ORM, I'd stay away from a "full stack" framework if I were you. Python's WSGI standard gives you a ton of easy-to-use options that will give you just the features you need and even let you choose your style of working.

既然你明确地不想要一个ORM,如果我是你,我就会远离“完整堆栈”框架。Python的WSGI标准为您提供了大量易于使用的选项,这些选项只提供您需要的特性,甚至允许您选择自己的工作风格。

Here's an example: for URL dispatch you can use Routes, which ports over the URL dispatch style of Rails. Or you could combine Selector with WebOb if that style suits you more.

这里有一个例子:对于URL分派,您可以使用路由,该路径通过URL分派样式的Rails。或者你也可以把选择器和WebOb组合在一起如果那个样式更适合你的话。

For "layouts", you can use the powerful Jinja2 if you want templates that cannot run code. Or, Mako if you prefer to be able to mix a little code in with your templates. You can even use Deliverance to control the layout of pages that are composed from multiple apps and even multiple languages!

对于“布局”,如果需要不能运行代码的模板,可以使用功能强大的Jinja2。或者,如果您希望能够在模板中混合一些代码,那么可以使用Mako。您甚至可以使用Deliverance控制由多个应用程序甚至多种语言组成的页面的布局!

A full-stack web framework is nice in that it makes a bunch of choices for you, letting you pay attention just to the app your building. But, the choices I've listed above are a good collection to get you going building your own. If you head down that path, you'll find it easy to plug in Beaker for caching and sessions if you need them, or WebError to help you with debugging.

一个完整的web框架是很好的,因为它为你做了很多选择,让你只关注你的应用程序你的建筑。但是,我上面列出的选择是一个很好的集合,可以让你建立自己的。如果沿着这条路走下去,您会发现,如果需要的话,可以插入Beaker来进行缓存和会话,或者使用WebError来帮助您调试。

Personally, I'm a big fan of ORMs (particularly SQLAlchemy), but if you're looking to go ORM free and lightweight overall you can't beat combining the great WSGI components available in Python.

就我个人而言,我是ORM(特别是SQLAlchemy)的忠实粉丝,但是如果您希望实现ORM免费和轻量级,那么您就不能将Python中可用的WSGI组件组合起来。

#3


11  

Give web.py a try. It's very simple and may provide the minimalism that you are looking for.

给web。py一试。它非常简单,可以提供你正在寻找的极简主义。

#4


9  

Pylons.

塔。

It's much better than django, and doesn't come with a crappy ORM.

《被解救的姜戈》比《被解救的姜戈》要好得多,也没有什么糟糕的情节。

#5


8  

People already gave many answers concerning web application frameworks, but MVC (or any other paradigm) is not tied to web only. That's just for clarity.

人们已经给出了许多关于web应用程序框架的答案,但是MVC(或其他任何范例)并不仅仅局限于web。这只是为了清晰。

If you are about plain MVC, Pylons conforms to paradigm in a stricter way. Django interprets MVC and they call it model-template-view, but the idea of role separation is the same. Actual choice is a matter of personal taste, although none of these two I consider lightweigth (Pylons might seem lighter, but in fact is not, and recently Django gathered some additional weight - most likely you will not fit even small application like personal blog in 20MB resident memory).

如果您使用的是普通的MVC,那么Pylons将以更严格的方式遵循范例。Django解释了MVC,他们称之为model-template-view,但是角色分离的概念是一样的。实际的选择是一个个人喜好的问题,尽管我认为这两个都不是lightweigth (Pylons可能看起来更轻,但实际上不是,最近Django收集了一些额外的重量——最可能的是,在20MB的常驻内存中,你甚至都装不下个人博客这样的小应用程序)。

Of course, nothing will stop you from writing your own framework, eg. with WebOb. You can make it as light as you want (and learn many things trying).

当然,没有什么能阻止你编写自己的框架。WebOb。你可以让它变得像你想要的一样轻(并且学习很多尝试的东西)。

#6


6  

If you want something simple, without having to make your own framework, while still not being all inclusive (django), you might want to try CherryPy. It can use almost any dispatcher (Page Handler / URL routing system). You would also have to pick your own templating engine, Genshi is my favorite.

如果您想要简单的东西,而不需要创建自己的框架,同时又不包含所有内容(django),那么您可能需要尝试CherryPy。它可以使用几乎任何dispatcher(页面处理程序/ URL路由系统)。你也可以选择自己的模板引擎,源氏是我的最爱。

#7


6  

checkout https://github.com/salimane/bottle-mvc or https://github.com/salimane/flask-mvc . They are boilerplates that could get you started with controllers, models in separate folders. They are based on bottle and flask micro frameworks, no useless features, they give you the flexibility to plugin whatever modules you want.

签出https://github.com/salimane/bottle-mvc或https://github.com/salimane/flask-mvc。它们是样板文件,可以让你从控制器开始,在不同的文件夹中建立模型。它们基于bottle和flask微框架,没有无用的特性,它们给你灵活的插入任何你想要的模块。

#8


6  

When it comes to desktop applications Dabo is a good choice. It's a cross platform framework on top of wxPython which supports MySql, Postgresql, Firebird and Sqlite.

对于桌面应用程序,Dabo是一个不错的选择。它是wxPython之上的一个跨平台框架,支持MySql、Postgresql、Firebird和Sqlite。

#9


5  

You want web2py. Check it:

你想要web2py。检查:

  • don't care for ORM, just want it to work with MySQL
  • 不关心ORM,只想让它和MySQL一起工作

Web2py doesn't have a ORM, but it does have a syntactic wrapper over SQL that makes it much easier to do the SQL.

Web2py没有ORM,但是在SQL上有一个语法包装器,这使得执行SQL更加容易。

  • has configurable routes
  • 有可配置的路由
  • has support for layouts
  • 支持布局

...web2py has both of these.

…web2py有这两个。

And web2py is more lightweight than django/rails/whatever on pretty much all counts. It's VERY easy to learn. The hardest things about learning a MVC framework are the scripts, the ORM, and (with django) the template language. But web2py got rid of the scripts, simplified the ORM, and the template language is just python in a rad clever way.

web2py比django/rails/任何东西都轻。这很容易学。学习MVC框架最困难的事情是脚本、ORM和(使用django)模板语言。但是web2py去掉了脚本,简化了ORM,模板语言只是python的一个rad的巧妙方式。

#10


4  

Yes, I would say Django is definitely the way to go. Its modular design ensures that you can mix and match components (ORM, templating engine, URL dispatch, ...) Instead of being stuck with a component the framework provides you, you can replace it with any 3rd party equivalent instead.

是的,我想说,《被解救的姜戈》绝对是一条出路。它的模块化设计确保您可以混合和匹配组件(ORM、模板引擎、URL分派、…)与框架提供的组件不同,您可以使用任何第三方等效组件替换它。

#11


4  

Django!

Django !

Google App Engine uses it.

谷歌App Engine使用它。

I use it too for my own pet projects.

我也用它来做我自己喜欢的项目。

#12


3  

web2py! django calls a controller a view, 'nuf said.

web2py !django将控制器称为视图。

#13


3  

If you want simplicity use web2py or pylons. Django is good...but the learning curve is steep

如果您想要简单,请使用web2py或pylons。Django是好的…但是学习曲线是陡峭的

#14


2  

Django. You don't have to use the additional features, and it's well designed so you can mix-n-match 3rd-party libraries as needed.

Django。您不需要使用其他特性,而且它设计良好,因此您可以根据需要混合使用n-match 3 -party库。

#15


2  

I'm really new on Python but I tried quiet a few, specially Django and web2py. I loved the simplicity of web2py, I was able to create a site of medium complexity in a few days. It has an imprecessive sets of feature a DAL, code generation, HTML hlpers and for me the most important feature was the documentation in the site is quite complete.

我对Python非常陌生,但是我尝试了一些安静的方法,特别是Django和web2py。我喜欢web2py的简单性,我能够在几天内创建一个中等复杂度的站点。它有一个隐性的特性集一个DAL,代码生成,HTML hlpers,对我来说,最重要的特性是网站的文档相当完整。

#16


2  

I would take a look at Pylons; it is lightweight and fast.

我想看看电塔;它是轻量级和快速的。

#17


2  

I'm also on the Django boat. Here are a few reasons why:

我也在Django船上。以下是一些原因:

  • You'll likely save time with Django's admin interface in avoiding manual queries.
  • 使用Django的管理界面可以节省时间,避免手工查询。
  • Django's templating system is fantastic
  • Django的模板系统非常棒
  • Django has a WONDERFUL community, very eager to help (see #django on freenode)
  • Django有一个很棒的社区,非常渴望提供帮助(参见freenode上的# Django)

#18


-1  

Django is my recommendation.

Django是我的建议。

You can find an introduction to it here (a Google Tech Talk by Jacob Kaplan-Moss):

你可以在这里找到它的介绍(Jacob Kaplan-Moss在谷歌Tech上的演讲):

And you may also want to have a look at Adrian Holovaty's talk given at Snakes and Rubies, DePaul University:

你也可以看看Adrian Holovaty在DePaul大学对蛇和红宝石的演讲:

#19


-3  

While not all Python frameworks explicitly support MVC, it is often trivial to create a web site which uses the MVC pattern by separating the data logic (the model) from the user interaction logic (the controller) and the templates (the view).

虽然不是所有的Python框架都显式地支持MVC,但是创建一个使用MVC模式的web站点通常是很琐碎的,它将数据逻辑(模型)与用户交互逻辑(控制器)和模板(视图)分离开来。

http://docs.python.org/howto/webservers.html#model-view-controller

http://docs.python.org/howto/webservers.html模型-视图-控制器