URL Mapping from the Book Chapter 4 – Dispatching. These are the basics there’s more detail in the book.
The URL http://site.com/a/c/f maps to:
The function f()
in controller “c.py” in application “a“.
- If
f
is not present, web2py defaults to the index
controller function.
- If
c
is not present, web2py defaults to the default.py controller.
- If
a
is not present, web2py defaults to the init
application.
- If there is no
init
application, web2py tries to run the welcome
application.
- The extension
.html
is optional.
The extension .html
is assumed as default.
- The extension determines the extension of the view that renders the output of the controller function
f()
.
- The extension allows the same content to be served in multiple formats (html, xml, json, rss, etc.).
Web2py maps GET/POST requests of the form:
http://site.com/a/c/f.html/x/y/z?p=1&q=2
As before, to function f
in controller “c.py” in application a
and it stores the URL parameters in the request
variable as follows:
request.args = ['x', 'y', 'z']
request.vars = {'p':1, 'q':2}
request.application = 'a'
request.controller = 'c'
request.function = 'f'
request.url = url of request
request.ajax = False #by default
if request.ajax == True and wasInitiatedByAWeb2pyComponent:
request.cid = componentName
#python, #web2py