Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't serve static files from cherrypy

Tags:

cherrypy

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()
like image 313
Kylee Avatar asked Mar 25 '11 01:03

Kylee


1 Answers

Some ideas:

  1. In CherryPy 3.2+, try tools.staticdir.debug = True, combined with log.screen = True or some other more preferred logging setup. That will help more than anything I can guess at in this answer.
  2. Try 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).
  3. In CherryPy 3.1 and above, you usually need to call engine.block() after engine.start().
like image 145
fumanchu Avatar answered Sep 22 '22 04:09

fumanchu