`

关于Python的WEB开发框架的介绍

 
阅读更多

一、Django

Django
Django is oriented to programmers who deal mainly with content. The makers of Django are from the newspaper business. They say that they were often asked to implement certain features on their web site with tight deadlines. So they wrote their own framework. Django does not re-use many components. Even their way to access databases (the so called object-relational mapper) is home-made.

If you have similar requirements as Django's makers you will find that it is an excellent framework. But it is not meant to have its components replaced easily in case you don't like them. Their templating language is not very "pythonic" - it is a language of its own although an easy one. A nice feature is their admin frontend - it will create HTML forms for you to easily manage the data in your database. And it comes with a nifty way to map URLs to certain functions in your application based on regular expressions.

AJAX is basically possible with Django but not very comfortable. They have a web server built in but they suggest you run Django applications on an Apache with mod_python. One thing that can truly be said about Django: they have good marketing. Django is well documented, has a large community and there is even a book currently written. All in all Django is a "don't worry - be happy" framework that is tightly integrated and which will help you get things done quickly if you don't care too much which components it uses and don't expect all parts to look perfectly pythonic. It's a bit magical.

Django面向主要处理内容的程序员。Django的创建者们源自报纸商业服务。他们反映他们经常被要求短时间内在他们的网站上实现特定的特性。所以他们编写了他们自己的框架。Django并没有重用许多组件,即使他们连接数据库的方式(所谓的对象关系映射器)是自制的。

如果你有如同Django创建者类似的需求,你会发现这是个杰出的框架。但这不意味着万一你不喜欢他们便可以轻易替代他们。他们的模板语言并不十分的类似python——它有它自己的语言即使非常简单。一个非常好的特性是他们的管理后台——它会为你生成HTML格式来使你轻易管理你数据库中的数据。同时它与生俱来一种俏皮的方式在你基于正则表达式的应用程序中来定位URL到特定的功能。

AJAX在Django中基本支持但用起来并不十分舒服。它内置的web服务器但建议你用mod_python在Apache上运行应用程序。关于Django有一件事情是事实:它有很好的市场前景。Django有十分好的文档,有非常大的社区同时还有一本书正在编著。总的来说Django是一个“无需担心,高兴点”的框架,它紧密地集成同时如果你不对它使用了哪些部件过分在意同时不奢求所有的部分都完美地pythonic,它帮助你快速地完成任务。它是有些魔幻的。

小结:Django优点:文档支持完善,社区支持强大,admin管理后台很强大,语法魔幻。

缺点:对AJAX支持不够,组件较难替换。

二、TurboGears

Turbogears makes use of existing components. Their web server runs on CherryPy, their HTML templates come from Kid, they access databases through SQLObject and even include a good way to write interactive AJAX applications through the use of a Javascript library called Mochikit that is tightly integrated.

They make it easier than Django to replace certain components in case you don't like them. For example you can throw away SQLObject and use SQLAlchemy instead; although many parts of Turbogears still lack full support for SQLAlchemy. Turbogears's URL mapping scheme is less explicit. You can't tell what is supposed to happen for certain URLs. Instead a program of the same name as the first part of the URL is called. So the URLs the user sees may appear less nifty.

A nicer feature is their set of web-based utilities. Among them is their WidgetBrowser to browse the library of supplied form elements - or Catwalk - a database administration frontend similar to that which Django provides. Turbogears is well documented and has a large community, too. All in all Turbogears has nifty features like its widget library or a good set of utility functions that make life easier.

Its documentation is somewhat incomplete and contains recipes and examples rather than a nice reference. A move to SQLAlchemy has been publicly announced but many features currently only work well with SQLObject. Turbogears may be a nice choice for programmers who are scared by the magic of Django and like it a bit more explicit.

TurboGears由已经存在的部件构成。它的web服务器运行在CherryPy上,它的HTML模板来源于Kid,它通过sqlObject连接数据库甚至包含了一个很好的方式通过使用一个紧密集成的叫Mochikit的javascript库编写互动的AJAX应用。

相对Django,如果你不喜欢几个部件,TurboGears更容易替代它们。例如,你可以摒弃SQLObject而使用SQLAlchemy;即使TurboGears许多部分缺乏对SQLObject的完整支持。TurboGears的URL定位结构相对更不明确。对特定URL你并不清楚应将要发生什么。相反与URL第一部分相同名称的程序被唤起。所以使用者看到的URL会显得不如Django俏皮。

一个相对更好的特性是它基于网络的实用功能集合。一个浏支持文件的插件浏览器——或者Catwalk——一个数据库后端管理,类似于Django提供的。TurboGears有很好的文档同时也有很大的社区。总的来说TurboGears有极好的特性比如它的插件库或一个很好的实用功能集合,使你的工作更简单。

它的文档有些不完全包含秘诀和案例代码而不是很好的引用。向SQLAlchemy的迁移已经向公众宣布但当前许多特性只与SQLObject完全兼容。TurboGears是对那些对Django的魔幻有些恐惧喜欢明确的程序员来说是个很好的选择。

小结:TurboGears优点:文档支持较完善,社区支持强大,组件可替换,语法明确,很好的插件库,很好的网络实用功能集合。

缺点:文档不完全,对某些替代部件未提供完全支持,URL定位不明确。

三、Pylons

Pylons isn't exactly new but appears to have a smaller community than Django or Turbogears. That does not mean it's technically worse than other frameworks. It is unique in that it is more minimal and flexible than other frameworks. Basically you need to learn the basics of the components it uses. Next you need to understand howthese components are controlled from within a Pylons application. So Pylons is the glue between the components with an additional powerful package called "Webhelpers" that aids in many areas from AJAX to RSS feed creation.

Pylons' flexibility means that you can exchange the components very easily. You don't like SQLAlchemy? Use SQLObjects. You read that Myghty is superseded by Mako? Use Mako. Pylons may not always hold your hand but it will try to make it easy to use different components than what Pylons uses by default. And you will likely be happy with what Pylons offers by default. The components are carefully chosen by looking at what other web frameworks do wrong.

The documentation for Pylons is still lacking and there is no "Pylons Handbook" yet. It seems like some fans of Pylons tried it because they generally liked the idea of web frameworks but were frustrated with Django or Turbogears.Some say that Pylons is the Ruby-on-Rails written in Python.

Pylons确切说并不新但相对Django和TurboGears有社区小。这并不意味着技术上它比其它框架糟糕。它十分特殊,体现在它相对其它框架更加轻量化更加灵活。从根本上来说你需要了解它使用部件的基础。下一步你需要理解这些部件在一个Pylons应用中如何被控制。所以Pylons是通过一个附加的叫“webhelpers”能在许多领域把AJAX向RSS Feed创建提供帮助的非常给力的包在这些组件起胶水的作用。

Pylons的灵活性意味着你可以轻松地替换掉组件。你不喜欢SQLAlchemy?使用SQLObjects就好了。你了解到Myghty被Mako替代了?那就用Mako。Pylons也许并不会时刻与你肩并肩但它尝试着让使用不同组件比使用默认组件更加容易。同时,你可能你会喜欢Pylons提供的默认组件。通过观察别的web框架做错的地方Pylons精心挑选了组件。

针对Pylons的文档仍然十分缺乏。还没有一个Pylons手册。一些Pylons的追随者尝试过写它因为喜欢这个web框架的主意但被Django和TurboGears疑惑了。一些人说Pylons是用Python写的Ruby on Rails。

小结:Pylons优点:更加轻量化,更加灵活,可替换并支持完善的组件,默认组件吸收了其它web框架的经验。像Ruby on Rails。

缺点:文档十分缺乏,社区支持不够。需要了解各部件的基础知识和如何被控制。

我的话

本人自认为英语学得可以,但Python刚刚入门,对这些web框架也是只有一个初步的了解,谈不上任何实战经验,对于一些专业词汇翻译不够准确,:-)也算是增加些了解。

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics