Choose Your Own Pyventure/Webpy Hello World

From Wikibooks, open books for an open world
Jump to: navigation, search
''' A simple Hello,World in!'''

# make sure the 'web' dir from 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__":