Dynamic handling of ‘virtual file names’, or URL paths with file extensions

Well TurboGears uses CherryPY as the URL dispatcher. And by default
it uses the object structure as a tree like structure for the URL
paths, like the file system structure.

This works fine most of the time. However, the Python function name is
quite restrict than what we can use in an URL. For example, the “.”
character is not allowed. So, for example, if I want to make the URL
looks the old traditional way, like “/index.html”. I’ll need to write
a BIG elif clause in the default() function.

The good news is that after some digg on Google I found
This CherryPY ticket. And the solution is simple: I could use
index_html as the function name, and when user types index.html in the
URL, CherryPY will find index_html :)

Tags: , ,

Post a Comment

You could use <code type="name"> to get your code colorized

Your email is never published nor shared. Required fields are marked *

Close
E-mail It