cherrypy是python的一个模块,它本身就是一个HTTP服务器,使用相当方便,使用HTTP呈现一些东西相当的方便,直接用浏览器就可以观察到。
cherrypy的首页 http://www.cherrypy.org/ 上有这样一个例子:
import cherrypy
class HelloWorld(object):
def index(self):
return "Hello World!"
index.exposed = True
cherrypy.quickstart(HelloWorld())
运行这个例子,就启动了一个轻量级的HTTP服务器外加一个简单的网页,打开浏览器,输入 127.0.0.1:8080 回车,你会看到熟悉的 "Hello World!"
在页面之间跳转:
import cherrypy
class HelloWorld:
def index(self):
return '<a href="zeus">hello world!</a>'
index.exposed = True
def zeus(self):
return "i am zeus, the king of god"
zeus.exposed = True
cherrypy.quickstart(HelloWorld())
页面必须用"exposed"函数导出才能有效。