Pylons  - 讨论区

标题:转:【翻译】The Definitive Guide to Pylons(四)

2010年10月22日 星期五 16:59

Python Language
Python语言

Python is a fantastic language for a huge range of programming problems. It is easy to learn and yet powerful and expressive enough to handle all manner of tasks. It is also great for web programming (there are good reasons it is one of the three official languages at Google). Perhaps its key benefit though is that Python has a great deal of support across all popular platforms including BSD, Linux, MacOS X and Windows and a huge range of software libraries already available for it so the majority of the time you will be able to find a suitable tool for the task you are trying to achieve without having to write it yourself.

Python是一个奇妙的语言,可以处理大量的各种编程问题。Python很容易学习,且强大的表现足以处理所有的任务。在网络编程也是非常的出色(有很好的理由是它是Google的三种官方语言之一)。也许它的主要好处是,Python几乎支持所有流行的平台,包括BSD,Linux,MacOS X和Windows,并且Python有大量的软件库,因此,大部分时间你将能够找到一个合适的工具,解决你的工作,而不必自己编写。

If you haven't yet learned Python now would be a good time to read the Python Tutorial at  http://docs.python.org/tut/tut.html  which will give you all the knowledge you need to get started developing applications with Pylons.

如果您尚未了解到Python,现在将是一个很好的时间阅读了Python教程,网址在 http://docs.python.org/tut/tut.html ,它将给你所有需要的知识,作为开发用Pylons开发应用的起点。

Another good source of information for learning Pylons is Mark Pilgrim's book Dive Into Python published in 2004. It is freely available online at http://www.diveintopython.org/toc/index.html  and goes into a bit more detail about Python's introspection.

另一个学习Pylons的好资料,是Mark Pilgrim的“Dive Into Python”,于2004年出版。它是免费在线提供的,可以使你更详细的了解Python,网址在 http://www.diveintopython.org/toc/index.html


Python 3.0
Python 3.0 is a new version of the Python programming language which is currently in Alpha release. Unlike recent upgrades to the Python programming language Python 3.0 will not be fully backwards compatible with previous versions so it is likely that code written for Pylons at the moment, will not automatically work with Python 3.0.

Python 3.0是一个Python编程语言的新版本,目前处于测试阶段。不同于最近与Python编程语言的升级,Python 3.0不会完全向后兼容以前的版本,很可能现在使用Pylons写的代码,将不会在Python 3.0中自动运行。

Luckily this isn't a problem you need to be too worried about for two reasons:

幸好这不是一个问题,你需要担心的原因有两个:

 • The changes in Python 3.0 are fairly small so it is going to be fairly easy to upgrade your code 
 • The Python language team will continue to release 2.x versions of Python after the 3.0 release 
 • A tool will be available to automatically translate Python source files from 2.x to 3.x and it will handle the vast majority of the conversions necessary. If you are interested, the current development version is at  http://svn.python.org/projects/sandbox/trunk/2to3/

 • Python 3.0变化相当小,可以相当容易升级您的代码
 • Python语言的团队在Python 3.0发布后,将继续发布2.x的版本
 • 有个工具可以自动将Python源文件从2.x转换到3.x,在中间工具将处理绝大多数必要的转换。如果你对于该工具有兴趣,目前的开发版本在这 http://svn.python.org/projects/sandbox/trunk/2to3/

Once there is enough demand for a Python 3.0 version of Pylons and enough of the Pylons dependencies have been updated the Pylons team plan to release a pair of feature-identical Pylons versions, one for Python 2.6 and one for Python 3.0 in line with the Python community's current recommendation.

一旦有足够的需求Python 3.0版的Pylons,以及Pylons依赖的组件已更新,Pylons团队则计划推出功能相同的两个Pylons版本,一个为Python 2.6和一个3.0为Python,符合Python社区目前的建议。

Python 2.6 will include a feature to print warning messages about any code which is not compatible with Python 3.0 so you will be able to run your code on Pylons for Python 2.6 to find out where any problems might be and then after making changes or running the 2to3 refactor tool you will be able to run your code on Pylons for Python 3.0.

Python 2.6包括一个特性,关于任何不兼容的Python 3.0的代码,将打印警告信息,因此您将能够在Python 2.6中运行您的Pylons代码,找出问题所在,再进行更改或运行2to3重构工具,你将能够在Python 3.0中运行您的Pylons代码。

The Pylons Community
Pylons社区

A key benefit of choosing Pylons is that there is a thriving and helpful community built around it. Getting active in the Pylons community is easy, and we're always looking to increase community participation.

选择Pylons一个关键的好处是,有一个欣欣向荣的和给予帮助的社区围绕着它。活跃在Pylons社区是很容易,我们一直在关注增强社区参与。

Besides the Official Documentation there is also a Pylons Cookbook which contains user-contributed documentation as part of the Pylons wiki. The community always welcomes new contributions to the Cookbook or comments on existing articles and if you register on the wiki you can even export to PDF by clicking the PDF icon in the top right of the pages to take on the road with you.

除了官方文档,也有Pylons Cookbook(Pylons食谱),其中有一部分是wiki中用户贡献出来的文档。社区总是欢迎新的文档贡献到食谱或对现有的文章的评论,如果你在wiki中注册,通过点击在当前的网页右上角的PDF图标,你甚至可以导出为PDF格式。

Pylons Wiki: http://wiki.pylonshq.com/
官方文档: http://wiki.pylonshq.com/display/pylonsdocs/
Cookbook: http://wiki.pylonshq.com/display/pylonscookbook/

For more direct help the Pylons Discuss mailing list on Google Groups is always active and there are usually quite a few people on the Pylons freenode channel on IRC who are happy to help too.

随时可以在Google Groups的Pylons Discuss邮件列表中得到更直接地帮助,并且通常有不少人在IRC的Pylons freenode频道,他们都乐于助人。

IRC:#pylons on freenode
邮件列表: http://groups.google.com/pylons-discuss

Pylons Components
Pylons组件
Unlike other frameworks where each component has been custom built for the framework and then tightly integrated into the other components of the framework, Pylons is more like a collection of very carefully chosen third party software. Rather than starting from scratch on each of the components which make up Pylons the developers instead worked with existing software teams to develop standards and APIs which would allow their software to work with Pylons.

其他框架的每个组件都已按照框架定制,然后紧密地集成到框架的其他组件,与其他框架不同,Pylons更像是仔细挑选的第三方软件的集合。组成Pylons的每一个组件不是从零开始,相反,开发者与现有的软件开发团队共同制定了一套标准和API,从而可以使他们的软件与Pylons一起工作。

This approach turns out to be hugely useful and has three core benefits:

这种做法却是非常有益的,有三个核心的好处:

 • The APIs and methodologies which allow Pylons to work with one class of component, say object relational mappers, also mean that when newer and better software comes along it is a simple task to use the same APIs and methodologies to allow Pylons to work with the new software. 
 • From the individual software project's point of view the APIs that have been developed to allow the software to work with Pylons also mean the software is much easier to integrate into other frameworks since the required APIs already exist. 
 • Because many of the components weren't initially designed just to be used in Pylons it also means you are much more likely to be able to use them in ways you wouldn't normally expect web framework components to be used in. For example FormEncode is also an excellent general purpose conversion library and SQLAlchemy is used in many projects entirely unrelated to the web. This means that as your applications grow or if your requirements change, Pylons is much more likely to be able to keep pace.

 • 这些API和方法,使的Pylons与某一类型的组件可以一起工作,如对象关系映射器(ORM),也意味着,当更新更好的软件出现,可以简单地使用相同的API和方法,使Pylons与新软件一起工作。
 • 从个人软件工程的角度来看,已制定的API,可以让软件与Pylons一起工作,也意味着该软件能非常容易地融入其他框架,因为需要的API已经存在。
 • 由于许多组件并非最初设计用于Pylons,这也意味着你更可能能够利用它们的方式,不必是你通常将它们被用作web框架组件的方式,例如FormEncode也是一个极好的一般用途的转换库,SQLAlchemy可以被用于与web无关的许多项目。这意味着,当你的应用程序扩大或如果您的需求变化,Pylons更容易跟进(弹性大)。

One of the problems for newcomers to Pylons is that it can be difficult to know how all the components fit together, particularly because the individual projects' documentation aren't necessarily web-focused. That's where this book comes in.

对于Pylons的初学者,一个问题是,Pylons很难知道所有的部件如何组合在一起,特别是由于个别项目的文档有可能不是网站的重点。这就是这本书的用武之地。


What's Coming Up
即将到来
Over the next 21 Chapters you'll learn everything you need to know to create a simple website with a navigation hierarchy, editable sections and pages, a comment system and tags support. The application will serve as a very good starting point for any Pylons-based website you create.

在接下来的21章您将了解一切您需要知道,去创建一个简单的网站导航层次,可编辑的部分和网页,评论系统和标签支持。这个web应用将成为一个很好的起点,创建任何以Pylons为基础的网站的起点。

The book is divided into three parts: Getting Started, Advanced Pylons and Expert Pylons. In the Getting Started part you'll learn:

这本书分为三部分:入门,高级Pylons和专题Pylons。在入门部分您将了解:
 • how to install Pylons on Linux, Mac or Windows in a way that doesn't interfere with other software on your system 
 • how to use templates to create customizable project skeletons to get you up and running quickly with Paste Script 
 • the basics of the HTTP protocol and how Pylons' request and response objects make working with it much easier 
 • the basics of the Pylons architecture and what each of the Pylons globals are for 
 • how to use Pylons' industry-leading interactive debugger, as well as email reporting tools 
 • how to create templates for your view layer with Mako as well as how to take advantage of features such as inheritance to apply consistent themes across multiple pages and how to use components to generate common structures such as navigational elements 
 • how to create forms using the Pylons helpers and how to validate and repopulate them as necessary using FormEncode and HTMLFill. 
 • how to deal with file uploads and repeating validation structures involving one-to-many mappings in your model 
 • the various software options for your model, whether it be an XML database, an Amazon S3 or SimpleDB store or a traditional relational database management system 
 • how you can use SQLAlchemy to model your database, saving you time and effort


 • 如何在Linux,Mac或Windows安装Pylons的方式,该方式并不干扰在您的系统中的其它软件
 • 如何使用模板来创建定制的项目骨架,使用Paste脚本开始和快速运行
 • 基本的HTTP协议以及Pylons的请求(request)和响应(response)对象是如何与之更容易地一起工作
 • Pylons基本架构和Pylons的全局变量(globals)
 • 如何使用Pylons中业界领先的交互式调试,以及email的报告工具
 • 如何用Mako为你的视图层创建模板,以及如何利用特性,如继承,在多个网页应用一致的主题,以及如何使用组件产生共同的结构,如导航元素
 • 如何使用Pylons helpers创建表单(form),以及如何验证和数据传入/回传(repopulate)表单,在必要时使用FormEncode和HTMLFill 。 
 • 如何处理文件上传和重复验证结构(涉及模型中的一对多映射)
 • 模型(Model)有关的各种参数,不管它是一个XML数据库,Amazon S3或SimpleDB store或传统的关系数据库管理系统
 • 如何使用SQLAlchemy建立你的数据库模型,以节省你的时间和精力

We'll also get started with our example application called SimpleSite so that you see how the techniques you've learned work in a real application.

我们也将开始使用我们的例子(SimpleSite),让你知道你所了解的技术是如何在一个真正的应用中工作的。

Once you've mastered the basics we'll take a look at some of the more advanced features and techniques that can be used in Pylons applications. These include:

一旦你掌握了基本知识我们将看看一些可用于Pylons应用的更先进的功能和技术。包括:

 • how to use Routes to allow complex mappings between the URLs your application handles and the code that powers them as well as best practices for URL design and how URLs can be used as simple state stores 
 • what Unicode is and how to use it throughout your Pylons application 
 • how to write a Pylons application which supports multiple languages and displays non-Western characters such as Japanese or Arabic 
 • the YUI library and how it can be used to simplify your client side CSS and layouts 
 • the basics of the JavaScript language including the areas where it differs from Python 
 • how to use AJAX, animation and drag and drop to improve your web applications 
 • how to write effective unit and functional tests 
 • how to use docstrings and reStructuredText to quickly and easily write good documentation for your Pylons project.


 • 如何使用Routes,使得在你的应用程序处理的URLs和支持它们的代码之间做复杂的映射,以及如何最佳地设计URL,如何用URLs作简单的状态的保存
 • Unicode和如何在你的Pylons应用中使用它
 • 如何建立一个Pylons应用,支持多国语言,并显示非西方字符如日文或阿拉伯文
 • YUI库,以及如何使用它简化你的客户端的CSS和布局
 • 基本的JavaScript语言,包括在哪些领域不同于Python
 • 如何使用AJAX技术,动画(animation)和拖放(drag and drop),以改善您的Web应用程序
 • 如何撰写有效的单元和功能测试
 • 如何使用docstrings和reStructuredText快速,轻松地为你的项目书写良好的文档。

We'll then return to the SimpleSite example and add a navigation hierarchy, CSS and JavaScript to the example application as well demonstrating some advanced SQLAlchemy features such as inheritance.

然后,我们会返回到SimpleSite,并添加导航层次,CSS和JavaScript到SimpleSite,以及SQLAlchemy中一些先进的功能,如继承。

Once you've mastered these techniques you'll learn all about Pylons' internal structure and how you can easily use a specification called the Web Server Gateway Interface to extend or change the way Pylons itself works. We'll cover:

一旦你掌握了这些技术,您将会了解到所有有关Pylons的内部结构,以及如何可以轻松地使用WSGI规范(Web服务器网关接口),以扩展或改变Pylons的工作方式。我们将涵盖:

 • the Web Server Gateway Interface specification and the details of how to program various types of Web Server Gateway Interface component 
 • a bit about the history of Pylons and how it influences the design methodology 
 • how Pylons uses Paste Deploy and egg entry points to allow easy customization of middleware and applications in configuration files 
 • how Pylons uses the egg format and setuptools to allow easy packaging and distribution of Pylons applications and dependencies on the Python Package Index 
 • how Paste Script can be used with the websetup.py file to allow users of your application to quickly setup your application 
 • how to use AuthKit to implement authentication and authorization appropriate to your application's needs 
 • the principles of various ways web applications can be written including multi-threaded, multi-process and asynchronous and why most deployment options for Pylons are multi-threaded 
 • how to deploy a Pylons application using Apache or Nginx proxying to a Paster server. How to use mod_wsgi to embed a Pylons applications in an Apache server. Where to learn about the many other ways to deploy Pylons applications. 
 • how to use Python's powerful logging system with a Pylons application

 • WSGI(Web服务器网关接口)规范和如何建立不同类型的WSGI组件的细节
 • 一点关于Pylons的历史以及它如何影响方法的设计
 • Pylons如何使用Paste部署和egg entry points,使得中间件和应用在配置文件中易于定制
 • Pylons如何使用egg格式和setuptools,使Pylons应用和在Python Package Index的依赖(dependencies)容易打包及发布
 • 如何使用Paste脚本和websetup.py,使得你的用户快速安装你的应用程序
 • 如何使用AuthKit,以适合您应用的需要,实施认证和授权
 • web应用建立的各种原则,包括多线程,多进程和异步,以及为什么Pylons大多数的部署选项是多线程的
 • 如何部署使用Apache或Nginx代理的Paster服务器的Pylons应用。如何使用mod_wsgi在Apache服务器嵌入Pylons应用。从何处可以了解许多其他的方式来部署Pylons应用。
 • 如何使用Python强大的logging系统,将之用于Pylons应用

We'll then take a final look at the SimpleSite application and see how to turn the project back into a template so that other people can use it as a starting point for their own applications.

然后,我们会最后看看SimpleSite,了解如何将该项目转换为一个模板,以便其他人可以使用它作为一个自己的应用程序的起点。

By the end of the book you should have a thorough understanding of how to use Pylons but hopefully also have a good knowledge of the technologies Pylons uses and the underlying reasons for their inclusion in the Pylons framework so that you are empowered to make your own choices about which components to use in your Pylons application.

到了这本书的结尾,你应该有一个透彻的关于如何使用Pylons的认识,也预期知道Pylons使用的技术的知识,以及它们在Pylons框架中的底层工作原理,从而使你有能力作出自己的选择,在Pylons应用中使用哪些组件。

Pylons is a framework that is designed to work with you and not to enforce its view of the world on your project. This book will give you the skills you need to use Pylons' default options but also to know when to break the rules.

Pylons是一个框架,目的是与你一道工作,而不是将它的哲学强制赋予您的项目。这本书会给你需要的使用Pylons的默认选项的技能,但也知道何时打破规则。


Summary
总结

This chapter has given you a broad understanding of some of some of the design philosophies of Pylons and what makes it slightly different from other frameworks you might have come across.

这一章给你一个大概的了解,关于Pylons的一些设计理念,以及它与你可能会遇到的其他框架略的不同之处。

There's clearly a lot to learn so let's get started!

显然还有很多东西要学习,所以让我们开始吧!

原文: http://hi.baidu.com/zhuifengdenanhai/blog/item/e0a27ecfb656993af9dc6153.html

如下红色区域有误,请重新填写。

    你的回复:

    请 登录 后回复。还没有在Zeuux哲思注册吗?现在 注册 !

    Zeuux © 2024

    京ICP备05028076号