Search code examples
pythontwisted

Twisted: putChild AttributeError while building site tree


I'm trying to implement site tree using the following code:

root = Root()
a = root.putChild("login", login())
b = root.putChild("user", user())
c = b.putChild("register", register())

I expect the it will generate structure like this:

http://www.example.com/login
http://www.example.com/user
http://www.example.com/user/register

But, unfortunately I receive the following error message instead:

2013-10-11 19:33:15+0300 [-] AttributeError: 'NoneType' object has no attribute 'putChild'

Please assist.


Solution

  • Is user a class implementing twisted.web.resource.IResource?

    In that case,

    u = user()
    root.putChild("user", u)
    u.putChild("register", register())
    

    Method putChild returns None, not the child as you seem to have expected.