To access applications globally through the internet it is important to host them. For that web applications need an HTTP server. CherryPy provides its own, production ready, HTTP servers. There are two ways to host an application in CherryPy:
The most straightforward way is to use cherrypy.quickstart() function. It takes three arguments of which two are optional. First, the instance of the application to host. Second, the base path at which the application will be accessible from. Third, a configuration dictionary containing the settings to configure the application.
Eg.:
cherrypy.quickstart(Web())
cherrypy.quickstart(Web(), '/index')
cherrypy.quickstart(Web(), '/index', {'/': {'tools.gzip.on': True}})
The first example makes the application available at http://localhost:8080/ whereas the other two will make it available at http://localhost:8080/blog. In addition, the last one provides specific settings for the application.
The cherrypy.quickstart() does not work for hosting multiple applications. The cherrypy.tree.mount function is used for hosting multiple applications using CherryPy:
Eg.:
cherrypy.tree.mount(Web(), '/web_index', web_conf)
cherrypy.tree.mount(App(), '/app_index', app_conf)
cherrypy.engine.start()
cherrypy.engine.block()
Note that cherrypy.tree.mount() takes the same parameters as cherrypy.quickstart(): an application, a hosting path segment and a configuration dictionary. The last two lines are to start the application servers.
Comments