Search code examples
pythoncherrypy

cherrypy dynamically add objects


I'm using cherrypy to mimic an existing RESTful interface. One requirement is that I have is to be able to add objects on the fly.

So, for example, let's say I have an object, called myobj. I want to be able to expose a method that is based on an object added by the user. So, I would have an "add" context, where I create the object

http://example.ex/myobj+create

and I would be able to retrieve the object that's created, as well as any children:

http://example.ex/myobjs/obj1
http://example.ex/myobjs/obj1/child1

Is this possible with cherrypy? Should I be investigating a different framework?


Solution

  • Yes, you can add handlers dynamically. Just execute obj1.child1 = Child(...).