Eye of Hell Eye of Hell - 1 year ago 117
Python Question

How to use cherrypy as a web server for static files?

Is it any easy way to use CherryPy as an web server that will display

files in some folder? All CherryPy introductory documentation states that content is dynamically generated:

import cherrypy
class HelloWorld(object):
def index(self):
return "Hello World!"
index.exposed = True

Is it any easy way to use
instead of HelloWorld.index() method?

Answer Source

This simple code will serve files on current directory.

import os
import cherrypy

PATH = os.path.abspath(os.path.dirname(__file__))
class Root(object): pass

cherrypy.tree.mount(Root(), '/', config={
        '/': {
                'tools.staticdir.on': True,
                'tools.staticdir.dir': PATH,
                'tools.staticdir.index': 'index.html',