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

Mike Warren spam at mike-warren.com
Wed Nov 24 09:51:48 MST 2004


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

I haven't looked at web2 yet -- should I? (i.e. is this going to be
easier there?)


mike [at] mike [dash] warren [dot] com
gpg --keyserver --recv-key 579911BD
87F2 4D98 BDB0 0E90 EE2A 0CF9 1087 0884 5799 11BD

More information about the Twisted-web mailing list