CherryPy——基于Python的Web框架
CherryPy是什么(What is CherryPy)
CherryPy是一个基于Python的面向对象的HTTP框架。使用CherryPy来开发Web Application是非常轻松的。但CherryPy并没用提供一种类似于PHP的templating语言机制。
以下的内容摘自CherryPy Tutorial:
CherryPy is a pythonic, object-oriented HTTP framework. It provides the foundation over which complex web-based applications can be written, with little or no knowledge of the underlying protocols.
As an HTTP framework, CherryPy does all that is necessary to allow Python code to be executed when some resource (or URL) is requested by the user. However, it is not a templating language, such as PHP.
CherryPy的运行机制(How does CherryPy work)
CherryPy将URL映射到Python可调用对象(Python callable)来完成HTTP请求。以下的内容摘自CherryPy Tutorial:
Publishing objects
Any object that is attached to the root object is said to be published. This means that the object is accessible via the internal URL-to-object mapping routine. However, it does not mean that the object itself is directly accessible via the Web. For this to happen, the object has to be exposed.
Exposing objects
CherryPy maps URL requests to objects and calls the suitable method automatically. The methods that can be called as a result of external requests are said to be exposed.
Finding the correct object
For the user, a web application is just like a website with static files. The user types (or clicks) a URL, and gets to the desired webpage. A conventional webserver uses the URL to retrieve a static file from the filesystem. On the other hand, a web application server not only serves the content from static files; it can also map the URL it receives into some object and call it. The result is then sent back to the user's browser, where it is rendered into a viewable page. The result is a dynamic web application; for each URL, a unique object can be called into