Http server

Gert Cuykens gert.cuykens at gmail.com
Tue Dec 19 17:35:53 EST 2006


> > The cute secretary's name is "cherrypy.tools.staticdir".
> > Check out her resume at http://www.cherrypy.org/wiki/StaticContent
>
> I think i am in love :)

Cant believe this just works out

<code>
import os.path
import cherrypy
pwd = os.path.dirname(os.path.abspath(__file__))

class Http:

    _cp_config = {'tools.sessions.on': True}
    @cherrypy.expose
    def index(self):
        f = open(os.path.join(pwd, '../htm/index.htm'))
        xml = f.read()
        f.close()
        return xml

if __name__ == '__main__':
    cherrypy.config.update({'server.socket_port': 8080,
                            'server.thread_pool': 10,
                            'environment': 'production',
                            'log.screen': True})
    conf = {'/': {'tools.staticdir.root': os.path.join(pwd, '../htm')},
            '/css': {'tools.staticdir.on': True,
                     'tools.staticdir.dir': os.path.join(pwd, '../css')},
            '/js': {'tools.staticdir.on': True,
                    'tools.staticdir.dir': os.path.join(pwd, '../js')}}
    cherrypy.quickstart(Http(), '/', config=conf)
</code>



More information about the Python-list mailing list