Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 托管静态文件和应用程序_Python_Cherrypy - Fatal编程技术网

Python 托管静态文件和应用程序

Python 托管静态文件和应用程序,python,cherrypy,Python,Cherrypy,我正在努力让CherryPy同时托管静态文件和RESTAPI。我希望API在http://127.0.0.1:8080/api,以及http://127.0.0.1:8080/。当用户刚刚获取/apiURL时,我希望它提供一个静态HTML,并附带一个如何使用api的手册。/URL上的静态html是HTML5应用程序;RESTAPI的基本实现 我现在拥有的是: cherrypy.config.update({"tools.staticdir.on": True }) cherrypy.config

我正在努力让CherryPy同时托管静态文件和RESTAPI。我希望API在
http://127.0.0.1:8080/api
,以及
http://127.0.0.1:8080/
。当用户刚刚
获取
/api
URL时,我希望它提供一个静态HTML,并附带一个如何使用api的手册。
/
URL上的静态html是HTML5应用程序;RESTAPI的基本实现

我现在拥有的是:

cherrypy.config.update({"tools.staticdir.on": True })
cherrypy.config.update({"tools.staticdir.dir": "/home/bart/html" })
#cherrypy.config.update({"tools.staticdir.index": "index.html"})

if __name__ == '__main__':  
    cherrypy.tree.mount(myApp(), "/api")

    cherrypy.engine.start()
    cherrypy.engine.block()
它几乎就在那里,除了当我http://127.0.0.1:8080/api
,其作用与上的相同。
myApp()
类的
索引如下所示:

@cherrypy.expose
def index(self):
    # TODO: place API docs here
    if cherrypy.request.method == "GET":    
        return "REST API v{v}".format(v=VERSION)
    else:
        return result(405)

我通过为一个空的应用程序创建一个单独的配置来实现它:

cherrypy.tree.mount(myApp(), "/api")    
cherrypy.tree.mount(None, "/", {'/':
    {"tools.staticdir.on": True ,
    "tools.staticdir.dir": "/home/bart/html" ,
    "tools.staticdir.index": "index.html"
    } } )
cherrypy.engine.start()
cherrypy.engine.block()
看看这个,我认为您的定义需要另一个页面处理程序来处理
/