3. Creating a first website: Hello, world !

At the same level as the demo/ directory, create a directory called hello/.

Go to the hello/ directory and create a file called Hello.cpy that contain the following lines:

CherryClass Root:
mask:
    def index(self):
        <html><body>
            Hello, world !
        </body></html>
3.1

To compile the file, type:

python ../cherrypy.py Hello.cpy

This will create a file called HelloServer.py, which contains everything to run the website (including an HTTP server). To start it, just type:

python HelloServer.py

To see the page, open a browser and type in the URL: http://localhost:8000/

What we've learned:

Now let's add some dynamic functionality to it...



Footnotes

... 3.1
You can either use 4 whitespaces or one TAB to indent your code. It is possible to use more or less than 4 whitespaces for indenting (for instance, 3 whitespaces) by using the -W option to tell CherryPy about it (for instance: -W 3). Please note that, unlike Python, one tab can never correspond to 2 indentation levels. It always corresponds to one indentation level.
See About this document... for information on suggesting changes.