[Twisted-Python] Help with child Resources

Samuel Reynolds sam at SpinwardStars.com
Sat Dec 6 13:00:30 EST 2003

<newbie-alert />

I'm trying to serve a resource with child resources within
a subdirectory of a directory served via "mktap web".

The url http://mydomain/myPath properly serves the root
resource, RootResource, from index.rpy.

The url http://mydomain/myPath/mysub returns
"404 - No Such Resource".

My resource classes and index.rpy are defined in the
attached files.

I tried changing isLeaf to 1 in RootResource, to force
the render method to be called instead of attempting to
find the sub-resource, but got the same result, so I
suspect that the search for the sub-path resource is
happening before RootResource is reached.

I suspect I've missed something relatively simple, but
I'm new to Twisted. Can someone point out what I'm
doing wrong?


- Sam

-------------- next part --------------
from twisted.web import resource

def DEBUG_RENDER( cls, request ):
	tmpl = "<html>" \
		"class = %s<br />" \
		"prepath = %s<br />" \
		"postpath = %s<br />" \
	return tmpl % (cls.__name__, request.prepath, request.postpath)

class SubResource( resource.Resource ):
    # No children
    isLeaf = 1
    def render(self, request):
    	return DEBUG_RENDER( self.__class__, request )

class RootResource( resource.Resource ):
    # Has children
    isLeaf = 0
    def render(self, request):
    	return DEBUG_RENDER( self.__class__, request )
    def getChild(self, path, request):
        if path == '':
            return self
        if path == 'mysub':
            return SubResource()
        # Terminal condition: don't recognize the name.
        return error.NoResource("No such child resource '" + name + "'")

resource = RootResource()

More information about the Twisted-Python mailing list