On 1/6/06, Clank <[EMAIL PROTECTED]> wrote:
>
> Newbie-Q. I have a gaggle of URLs of form
>
> /archive/<number>.html
>
> I want to update & serve their content dynamically; it's obvious how to
> get almost-there with URLs like
>
> /archive/?number=<number>
>
> but I want the old URLs to work.
>
> It's a MovableType site, so there are probably other people with my
> problem. Is there a plausible answer in TG, or do I need to (say) run
> behind Apache and use mod_rewrite on those URLs?

What you want is to expose a default() method. Take a look at page 4
of the 20-minute Wiki tutorial, on
http://www.turbogears.org/docs/wiki20/page4.html, for an example. Have
/archive point at a class that looks something like the following:

class ArchiveByNumber(object):
    @turbogears.expose(html="...")
    def default(self, number):
        if number.endswith('.html'):
            number = number[:-5]
        if number.endswith('.htm'):
            number = number[:-4]
        number = int(number)  # In actual code, you'd use a validator here
        # Fetch the appropriate page from the database

The default() method will take any remaining URL components and
receive them as arguments. If you had, for example:

class Archive(object):
    @turbogears.expose(html="...")
    def default(self, *args):
        logDebug("Received args %s...", args)

And your user fetched the URL "/archive/2004/11/30/my-blog-post.htm",
your function would log "Received args ('2004', '11', '30',
'my-blog-post.htm')..."

I hope this helps.

--
Robin Munn
[EMAIL PROTECTED]
GPG key 0xD6497014

Reply via email to