6.2. Smart urls

The normal way to pass parameters to a script is to use query strings in the url, or post data. An alternative is to pass parameters as a part of the url, like in http://host/path/script.py/foo/bar ; here the parameters to the script are foo and bar

In the script you can access these additional parameters as a list ; it is an attribute of THIS, THIS.args :

print "The parameters are %s" %THIS.args

A problem with these urls is that if you want to use Include() or write a relative link or insert an image or a JavaScript, the url must be different if the script was called without a subpath or with any number of parameters in the subpath

For instance if you write this relative url in the script :

print '<IMG SRC="images/pic.png">'

and you call the script with http://host/path/script.py/foo/bar, the browser will compute the absolute url http://host/path/script.py/foo/images/pic.png, and execute the same script with the parameters foo,images,pic.png - not what you want !

To get the right url, use function THIS.rel() this way :

print '<IMG SRC="%s">' %THIS.rel("images/pic.png")

THIS.rel prepends to the relative url provided as argument as many '../' as the number of parameters