0

I read through the tutorial on the cherrypy website, and I'm still having some trouble understanding how it can be implemented in a modular, scalable way.

Could someone show me an example of how to have cherrypy receive a simple http post to its root, process the variable in some way, and respond dynamically using that data in the response?

4

2 に答える 2

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でブラウザを開きます

于 2009-12-31T06:21:20.127 に答える
1

このような例を求めていますか?

http://www.cherrypy.org/wiki/CherryPyTutorial#ReceivingdatafromHTMLforms

フォームからの入力を受け取ります。

CherryPyメソッド関数から任意のテキストを返すことができるため、入力に基づく動的テキストは非常に簡単です。

于 2009-12-30T21:58:37.993 に答える