Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

33 lines (22 sloc) 0.976 kb
layout title
default
Basic Application

Basic Application

Other languages : français | ...

The basic application defines a pairing of urls to class mappings. In the example below, the urls variable defines a pairing of a regular expression to a class name.

When a user access a resource, runs through the list of url regular expressions. If a url matches the regex, the class is instantiated, and the method 'GET' or 'POST' is called based on the http method. Data returned from the GET or POST is displayed in the browser.

If the requested url doesn't match any regex, a 404 is returned.

Example

import web

urls = (
    '/(.*)', 'hello'
)
app = web.application(urls, globals())

class hello:        
    def GET(self, name):
        if not name: 
            name = 'World'
        return 'Hello, ' + name + '!'

if __name__ == "__main__":
    app.run()
Jump to Line
Something went wrong with that request. Please try again.