Karrigell/Write the "Hello world" script

From Wikibooks, open books for an open world
< Karrigell
Jump to: navigation, search

Create a new directory. Save this script in a file called "index.py":

def index():
    return "Hello world"

Create another script called server.py:

import Karrigell

Save server.py in the same folder as index.py, then run it : python server.py. This will launch the built-in web server.

Finally, in a web browser enter the address http://localhost/index.py/index . Congratulations, you just ran your first Karrigell script ! The address index.py/index requested to run the function index() in the script index.py. The value returned by this function is printed in the web browser.

In fact, you could have written the url http://localhost/index.py : if no function name is specified, the function index() is run by default, with no argument.

And you could even have called http://localhost : if no script is specified, the server searches a script called index.py and if it finds one, it executes its function index().