我尝试了大约5个小时,现在将图像显示在我的网页上。 我的代码是这样的:CherryPy无法显示图像
import os
import cherrypy
file_path = os.getcwd().replace("\\", "/")
class Home:
def index(self):
return """<img src="img/logolong.jpg" alt="Main Page" />"""
index.exposed = True
if __name__ == "__main__":
cherrypy.server.socket_host = "127.0.0.1"
cherrypy.server.socket_port = 50505
config = {"/static":
{"tools.staticdir.on": True,
"tools.staticdir.dir": file_path,
},
"/images":
{"tools.staticdir.on": True,
"tools.staticdir.dir": file_path+"/img"}
}
cherrypy.tree.mount(Home(), "/", config=config)
cherrypy.engine.start()
cherrypy.engine.block()
我到处搜寻,并试图像一切。我使用Google Chrome和Windows7。
非常感谢您的帮助!
这是一个问题,你应该问CherryPy的作者。 – Arran
当您尝试直接访问图像时会发生什么? 404是否? – Blender
您是不是在寻找'/ img/img/logolong.jpg'中的图片?配置设置看起来像设置图像的位置,所以当你在索引中引用它时,你不需要'img /'。 –