[web.py] Piece#1 – Getting my hand dirty with some code.

I’m starting with the official tutorial on webpy.org site, which can be found at http://webpy.org/docs/0.3/tutorial 

They introduce a little bit about URL, which results at the using of it in code by using a list of mapping URL, something like:

url = (

 ‘/’ , ‘index’

The first part, ‘/’ ( slash) is the regex ( regular express) that is used to represent the URL. Here we got a slash only , that mean the root directory of our web app.  And text “index” is the name of class ( or ‘Handler’ class )  that will handle the request to this corresponding URL(s). URL in plural because we may have multiple urls that qualifies the regex definition here.

Next, we need to define the ‘hander’ class called ‘index’ that we mentioned above.

class index:

def GET(self):

               return “Hello GET request”

And we can start our very first app now by:

if __name__ == “__main__”:
          app = web.application(url, globals())

Ola, we’re done with the very simple app.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: