Reputation: 486
I am new to cherrypy and am trying to mount a simple hello world application but it keeps returning "NotFound: (404, "The path '/' was not found.")", but I have defined it.
Here's what I got,
In the __init__.py
import cherrypy
from HomeNetMain import HomeNetMain
cherrypy.config.update("global.cfg")
#I have tried "" for the script name parm but that doesn't work
cherrypy.tree.mount(HomeNetMain,"/","main.cfg")
cherrypy.engine.start()
cherrypy.quickstart()
In another file I have
import cherrypy
class HomeNetMain:
@cherrypy.expose
def index(self):
return "Hello World"
I have tried with both the decorator and index.exposed=True to no avail (sub question what is the preferred method for cherrypy the decorator or index.exposed)
global.cfg
[global]
server.socket_host: "127.0.0.1"
server.socket_port: 9080
log.screen: True
log.error_file: "/tmp/cherrypy.error"
log.access_file: "/tmp/cherrypy.access"
main.cfg
[/]
log.screen: True
log.error_file: "/tmp/homenet.error"
log.access_file: "/tmp/homenet.access"
I appreciate any help, thanks in advance.
edit
Here is the full stacktrace
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/CherryPy-3.2.2-py2.7.egg/cherrypy/_cprequest.py", line 656, in respond
response.body = self.handler()
File "/usr/local/lib/python2.7/dist-packages/CherryPy-3.2.2-py2.7.egg/cherrypy/lib/encoding.py", line 188, in __call__
self.body = self.oldhandler(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/CherryPy-3.2.2-py2.7.egg/cherrypy/_cperror.py", line 386, in __call__
raise self
NotFound: (404, "The path '/' was not found.")
Upvotes: 5
Views: 8240
Reputation: 486
Turns out I shouldn't have been using cherrypy.quickstart() I changed the code to the following and it worked fine
cherrypy.engine.start()
cherrypy.engine.block()
Upvotes: 4
Reputation: 57318
The class HomeNetMain is being mounted, instead of the instance. Since index is not a classmethod, a TypeError will be thrown which the framework is handling as 404.
cherrypy.tree.mount(HomeNetMain(), "/", "main.cfg")
Upvotes: 0