URL function generates internal URL paths for the actions and the static files.
Here is an example:
is mapped into
Notice that the output of the URL function depends on the name of the current application, the calling controller, and other parameters. web2py supports URL mapping and reverse URL mapping. URL mapping allows you to redefine the format of external URLs. If you use the URL function to generate all the internal URLs, then additions or changes to URL mappings will prevent broken links within the web2py application.
You can also use the URL function to generate URLs to actions in other controllers and other applications:
It is also possible to specify application, controller and function using named arguments:
URL(a='a', c='c', f='f')
If the application name a is missing the current app is assumed.
If the controller name c is missing, the current one is assumed.
Instead of passing the name of a controller function it is also possible to pass the function itself
For the reasons mentioned above, you should always use the URL function to generate URLs of static files for your applications. Static files are stored in the application's static subfolder (that's where they go when uploaded using the administrative interface). web2py provides a virtual 'static' controller whose job is to retrieve files from the static subfolder, determine their content-type, and stream the file to the client. The following example generates the URL for the static file "image.png":
is mapped into
If the static file is in a subfolder within the static folder, you can include the subfolder(s) as part of the filename. For example, to generate:
one should use:
You do not need to encode/escape the args and vars arguments; this is done automatically for you.
An optional list of names of variables from the URL query string (i.e., GET variables) to be included in the signature. It can also be set to True (the default) to include all variables, or False to include none of the variables.