On Feb 19, 2011, at 10:05 PM, Ross Peoples wrote:
> That makes sense. So let me ask you this: would it be possible to
> programatically add to routes_in and routes_out? I know this is probably
> getting a little silly, but I really like a specific URL structure. So if I
> used /posts/ for posts and /pages/ for pages, and the user created an about
> page, could I programatically add ('/about', 'SiteNet/default/pages/about')
> to routes.py?
Maybe. Alternatively, the /SiteNet/default/about function could check to see
whether the user had added an 'about' page and display it. Not as open-ended.
I say "maybe" for this reason: you can call rewrite.load to reload routes.py
after it changes. In support of unit testing, I changed rewrite.load so you can
call it with a data buffer (string) that gets used instead of the contents of
routes.py. It's not a documented feature, though, which means it's subject to
change.
I'm considering an enhancement to the new routers rewriter for a similar
purpose, and it might answer your requirement. Suppose your default path is
/myapp/default/index. You'd add this entry:
functions = ['index', 'user', test', 'other']
Then an incoming URL like /about would map to /myapp/default/index/about
and indeed any URL like that would do so *provided* that the first element is
a) not a defined application, b) not a defined controller in the default
application, and c) not a defined function in the default controller of the
default application.
Would that do it for you? The above line would be all you'd add to the routers
dict. Note that that's *not* in the current release.