How to use cherrypy as a web server for static files?
This simple code will serve files on current directory.
import osimport cherrypyPATH = os.path.abspath(os.path.dirname(__file__))class Root(object): passcherrypy.tree.mount(Root(), '/', config={ '/': { 'tools.staticdir.on': True, 'tools.staticdir.dir': PATH, 'tools.staticdir.index': 'index.html', }, })cherrypy.quickstart()
Here is some information on serving static content with CherryPy: http://docs.cherrypy.org/stable/progguide/files/static.html
BTW, here is a simple way to share the current directory over HTTP with python:
# Python 3$ python -m http.server [port]# Python 2$ python -m SimpleHTTPServer [port]
# encode: utf-8import cherrypyWEB_ROOT = "c:\\webserver\\root\\"class CServer( object ) : @cherrypy.expose def do_contact(self, **params): passcherrypy.server.socket_port = 80# INADDR_ANY: listen on all interfacescherrypy.server.socket_host = '0.0.0.0'conf = { '/': { 'tools.staticdir.on' : True, 'tools.staticdir.dir' : WEB_ROOT, 'tools.staticdir.index' : 'index.html' } }cherrypy.quickstart( CServer(), config = conf )