If you have a virtualenv and CherryPy is already installed in it, create a file hello.py
:
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
import cherrypy
class HelloWorld(object):
@cherrypy.expose
def index(self):
return 'Hello World!'
@cherrypy.expose
def greet(self, name):
return 'Hello {}!'.format(name)
cherrypy.quickstart(HelloWorld())
Then execute the file: $ hello.py
or $ python hello.py
. You should see output similar to this:
user@computer /develop/myapp $ python hello.py
[06/Nov/2016:05:58:44] ENGINE Listening for SIGTERM.
[06/Nov/2016:05:58:44] ENGINE Bus STARTING
[06/Nov/2016:05:58:44] ENGINE Set handler for console events.
CherryPy Checker:
The Application mounted at '' has an empty config.
[06/Nov/2016:05:58:44] ENGINE Started monitor thread '_TimeoutMonitor'.
[06/Nov/2016:05:58:44] ENGINE Started monitor thread 'Autoreloader'.
[06/Nov/2016:05:58:45] ENGINE Serving on http://127.0.0.1:8080
[06/Nov/2016:05:58:45] ENGINE Bus STARTED