2009-12-30 89 views
0

我通讀了cherrypy網站上的教程,我仍然在理解如何以模塊化,可擴展的方式實現它的過程中遇到一些困難。無法理解CherryPy

有人能告訴我一個如何讓cherrypy收到一個簡單的http post到其根目錄,以某種方式處理該變量,並在響應中使用該數據動態響應的示例?

回答

3
from cherrypy import expose 

class Adder: 
    @expose 
    def index(self): 
     return '''<html> 
        <body> 
        <form action="add"> 
         <input name="a" /> + <input name="b"> = 
         <input type="submit" /> 
        </form> 
        </body> 
        </html>''' 

    @expose 
    def add(self, a, b): 
     return str(int(a) + int(b)) 


if __name__ == "__main__": 
    from cherrypy import quickstart 
    quickstart(Adder()) 

運行該腳本,然後打開http://localhost:8080

瀏覽器