CherryPy Hello World error

前端 未结 10 1105
广开言路
广开言路 2020-12-31 07:32

When I am running CherryPy Hello World:

import cherrypy

class HelloWorld:
    def index(self):
        return \"Hello world!\"
    index.exposed = True

che         


        
10条回答
  •  太阳男子
    2020-12-31 08:11

    I think I had a similar problem when I started using CherryPy... But I can't remember exactly what it was... But the fix involved using a config file instead of passing the configs by hand:

    MyProj.conf:

    [global]
    server.socket_host = "127.0.0.1"
    server.socket_port = 8080
    server.thread_pool = 10
    

    MyProj.py

    import os
    import cherrypy
    
    class HelloWorld:
        def index(self):
            return "Hello world!"
        index.exposed = True
    
    # Assumes the config file is in the directory as the source.    
    conf_path = os.path.dirname(os.path.abspath(__file__))
    conf_path = os.path.join(conf_path, "MyProj.conf")
    cherrypy.config.update(conf_path)
    cherrypy.quickstart(HelloWorld())
    

    This definitely works here.
    I'm using Python 2.6.1 and CherryPy 3.1.1 and I run the script with -W ignore:

    c:\My_path> python -W ignore MyProj.py
    

    If you're under *nix, you should put the -W ignore in the #! comment at the top of the file.

提交回复
热议问题