Cannot use static files from cherry

I'm starting to learn cherrypy, but I ended up at a roadblock. I can’t get static files to save my life. I get 404. The path '/static' was not found.I have googled however not yet find a solution. All I want to do is files with files http: // localhost: 8080 / static

Sugions?

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()
+5
source share
1 answer

Some ideas:

  • In CherryPy 3.2+, try tools.staticdir.debug = True, in conjunction with log.screen = Trueor another preferred registration setting. This will help more than I can guess in this answer.
  • Give it a try tools.staticdir.dir = os.path.abspath(os.path.join(os.path.dirname(__file__), 'static')); it should be absolute (or if .dir is not absolute, then tools.staticdir.root should be).
  • CherryPy 3.1 engine.block() engine.start().
+6

All Articles