无法从cherrypy提供静态文件
我开始学习cherrypy,但遇到了障碍。我无法获得静态文件来挽救我的生命。我收到 404。找不到路径“/static”。
我已经用 google 搜索过,但尚未找到解决方案。我想做的就是在 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()
I'm starting to learn cherrypy but I've run in to a roadblock. I can't get static files to save my life. I'm getting a 404. The path '/static' was not found.
I've googled however have yet to find a solution. All I want to do is serve files at http://localhost:8080/static
Suggetions?
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()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
一些想法:
tools.staticdir.debug = True
结合log.screen = True
或其他一些更喜欢的日志记录设置。这比我在这个答案中所能猜测到的任何事情都更有帮助。Some ideas:
tools.staticdir.debug = True
, combined withlog.screen = True
or some other more preferred logging setup. That will help more than anything I can guess at in this answer.tools.staticdir.dir = os.path.abspath(os.path.join(os.path.dirname(__file__), 'static'))
; it needs to be absolute (or, if .dir is not absolute, then tools.staticdir.root needs to be).试试这个
并开始于
Try this
And started with