Jump to content

Choose Your Own Pyventure/Webpy Hello World

From Wikibooks, open books for an open world
''' A simple Hello,World in web.py!'''

# make sure the 'web' dir from web.py is in 
# the same directory
import web

# the url mapper, maps /(anything!) to the 
# 'hello' class.  
urls = (
    '/(.*)', 'hello'
)

# create the actual application
app = web.application(urls, globals())

# a class for handling url requests
# to handle requests, the class must have a 
# GET method that returns text 
class hello:        
    def GET(self, name):
        if not name: 
            name = 'world'
        return 'Hello, ' + name + '!'

# just include these 2 lines, which will seem magical for
# now, don't worry about it!
if __name__ == "__main__":
    app.run()