[Twisted-web] overriding resource getting with nevow+twisted

Donovan Preston dp at ulaluma.com
Wed Nov 24 14:42:40 MST 2004

On Nov 24, 2004, at 8:51 AM, Mike Warren wrote:

> Greetings,
> I want to invisibly remap URLs sometimes ("invisibly" to the client)
> and return basically an arbitrary resource for a URL but can't figure
> out how to do this within the getChild (etc.) machinery. My first
> inclination was to override locateChild, since I get the context there
> (and could, e.g., have an interface to get my remapped path). However,
> this never appears to get called -- the only thing which gets called
> on my root resource is getChildWithDefault, which is apparently being
> driven by twisted.web.resource's module-level getChildWithDefault
> which merely recurses the path looking for a leaf resource --
> precisely what I want to prevent.
> I could of course just re-assign the module-level getChildWithDefault,
> but this seems wrong, somehow -- is there a better way?
> (I am doing this because I want to implement aliases for some things
> -- e.g. I have URLs like /article/<ID> and want those to sometimes
> also be available at /some/other/url and I don't want clients to
> simply be redirected to /article/<ID>, which is sort of what happens
> if I just re-map the path in getPageContextForRequestContext)
> (Also, I may want to return different resources depending upon user
> preferences, although I'm not working on that precisely at the
> moment.)
> I haven't looked at web2 yet -- should I? (i.e. is this going to be
> easier there?)
> Thanks,

You are incorrectly using twisted.web.server.Site instead of 
nevow.appserver.NevowSite. NevowSite is the basis of what will become 
web2, yes. web2 is not yet usable.

If you are using mktap web, don't. Please look at any of the examples 
in the examples directory to see how to start a server using NevowSite.

Your use cases are absolutely, exactly what locateChild is for, so you 
were on the right track -- just heading down the wrong path ;-)


More information about the Twisted-web mailing list