gpt4 book ai didi

cherrypy - 无法提供cherrypy的静态文件

转载 作者:行者123 更新时间:2023-12-04 18:51:33 26 4
gpt4 key购买 nike

我开始学樱桃,但是遇到了路障。我无法获取静态文件来挽救生命。我正在搜索404。The path '/static' was not found.,但是尚未找到解决方案。我要做的就是在http://localhost:8080/static提供文件

建议?

import os
import cherrypy

class Root(object):
@cherrypy.expose
def index(self):
pass

config = {
'/static':{
'tools.staticdir.on': True,
'tools.staticdir.dir': os.path.join(os.path.dirname(__file__), 'static')
}
}

cherrypy.tree.mount(Root(), '/', config = config)
cherrypy.engine.start()

最佳答案

一些想法:

  • 在CherryPy 3.2+中,尝试tools.staticdir.debug = True,结合log.screen = True或其他一些更喜欢的日志记录设置。这将比我在此答案中可以猜测的任何东西都有用。
  • 尝试tools.staticdir.dir = os.path.abspath(os.path.join(os.path.dirname(__file__), 'static'));它必须是绝对的(或者,如果.dir不是绝对的,则需要是tools.staticdir.root)。
  • 在CherryPy 3.1及更高版本中,通常需要在engine.start()之后调用engine.block()。
  • 关于cherrypy - 无法提供cherrypy的静态文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5427639/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com