Method dispatcher wiki example problem

336 views
Skip to first unread message

Voltron

unread,
Oct 31, 2009, 4:22:06 AM10/31/09
to cherrypy-users
Taking the example from the wiki:

import cherrypy


class Root():
exposed = True

def __init__(self, *things):
self.things = list(things)

def GET(self):
return repr(self.things)

def POST(self, thing):
self.things.append(thing)

root = Root(1, 2, 3)

d = cherrypy.dispatch.MethodDispatcher()
conf = {'/': {'request.dispatch': d}}
cherrypy.tree.mount(root, "/", conf)
cherrypy.server.socket_port=8081

cherrypy.quickstart(root)


This fails with a traceback:


Traceback (most recent call last):
File "C:\Python26\lib\site-packages\cherrypy\_cprequest.py", line
606, in respond
cherrypy.response.body = self.handler()
File "C:\Python26\lib\site-packages\cherrypy\_cpdispatch.py", line
25, in __call__
return self.callable(*self.args, **self.kwargs)
AttributeError: Root instance has no __call__ method

Can someone tell me what I have done wrong? Thanks

Sylvain Hellegouarch

unread,
Oct 31, 2009, 5:07:03 AM10/31/09
to cherryp...@googlegroups.com
Voltron a écrit :

You are mounting the application with cherrypy.tree.mount and you do
provide the conf but then you override it with cherrypy.quickstart
without providing the conf.

Either:

cherrypy.tree.mount(root, "/", conf)
cherrypy.engine.start()
cherrypy.engine.block()

Or:

cherrypy.quickstart(root, "/", conf)

- Sylvain

Reply all
Reply to author
Forward
0 new messages