这是一个最小的示例:
import cherrypyclass Root(object): @cherrypy.expose def default(self, **kwargs): print kwargs return '''<form action="" method="POST">Host Availability:<input type="checkbox" name="goal" value="cpu" /> CPU idle<input type="checkbox" name="goal" value="lighttpd" /> Lighttpd Service<input type="checkbox" name="goal" value="mysql" /> Mysql Service<input type="submit"></form>'''cherrypy.quickstart(Root())
这是终端输出:
$ python stacktest.py [10/Sep/2010:14:25:55] HTTP Serving HTTP on http://0.0.0.0:8080/CherryPy Checker:The Application mounted at '' has an empty config.Submitted goal argument: None127.0.0.1 - - [10/Sep/2010:14:26:09] "GET / HTTP/1.1" 200 276 "" "Mozilla..."Submitted goal argument: ['cpu', 'mysql']127.0.0.1 - - [10/Sep/2010:14:26:15] "POST / HTTP/1.1" 200 276 "http://localhost:8003/" "Mozilla..."[10/Sep/2010:14:26:26] ENGINE <Ctrl-C> hit: shutting down app engine[10/Sep/2010:14:26:26] HTTP HTTP Server shut down[10/Sep/2010:14:26:26] ENGINE CherryPy shut down$
如您所见,CherryPy会将多个具有相同名称的控件收集到一个列表中。您不需要
[]后缀来告诉它执行此操作。然后,遍历列表以查看提交了哪些值。(请记住,如果仅选择一项,则
goal参数将是单个字符串而不是列表!)



