1

チェリーピーエッセンシャルでRoutesDispatcherの例を試しましたが、機能しませんでした。それは私にエラーを与えます。私Page not foundは何が欠けていますか?

import cherrypy
class Root:
    def index(self):
        return "Not much to say"
    def hello(self, name):
        return "Hello %s" % name
if __name__ == '__main__':
    root = Root()
    # Create an instance of the dispatcher
    d = cherrypy.dispatch.RoutesDispatcher()
    # connect a route that will be handled by the 'index' handler
    d.connect('default_route', '', controller=root)
    # connect a route to the 'hello' handler
    # this will match URIs such as '/say/hello/there'
    # but not '/hello/there'
    d.connect('some_other', 'say/:action/:name',
    controller=root, action='hello')
    # set the dispatcher
    conf = {'/': {'request.dispatch': d}}
    cherrypy.quickstart(root, '/', config=conf)
4

2 に答える 2

4

これはかなり前から解決されていることはわかっていますが、接続されたパスに開始スラッシュを追加することで、機能していないルートを修正できたことは注目に値します。

d.connect('some_other', 'say/:action/:name',

d.connect('some_other', '/say/:action/:name',

これが誰かを助けることを願っています。

于 2015-11-06T20:15:47.930 に答える
-1

Try exposing your handlers...

 @cherrypy.expose
 def index(self):
    return "Not much to say"
 @cherrypy.expose
 def hello(self, name):
    return "Hello %s" % name

Andrew

于 2012-07-31T13:03:23.363 に答える