views:

94

answers:

1

How do you assign a wsgi app to the root of cherrypy via the config file? I'd like the request "http://localhost:8080/" to route to my own wsgiapp. I'm using cherryd to start a cherrypy server with a config file as follows:

Here's the invocation:

cherryd --config config.cfg --import myapp

Here's the config.cfg file:

[global]
server.socket_host: "127.0.0.1"
server.socket_port: 8080
tree.apps: { "/" : myapp.wsgiapp  }

Here's the myapp.py module:

def wsgiapp(environ, start_response):
    start_response('200 OK', [('Content-Type', 'text/plain')])
    return ['Hello World']

Here's the error message:

  File "/Users/samwan/Documents/myproject/virtual_environment/lib/python2.5/site-packages/CherryPy-3.1.2-py2.5.egg/cherrypy/_cpconfig.py", line 331, in _tree_namespace_handler
    cherrypy.tree.graft(v, v.script_name)
AttributeError: 'dict' object has no attribute 'script_name'
+2  A: 

Honestly, I think we just hadn't considered that use case; it was designed to pass whole Application instances, not dictionaries of WSGI apps. You should be able to replace cherrypy.config.namespaces['tree'] with a handler that takes your dict pretty easily until we get this fixed. Make me a ticket and I'll see if we can get it into 3.2 final.

fumanchu
Ok, filed, thanks! (http://www.cherrypy.org/ticket/989)
Samuel Wan