[Twisted-Python] Basic Resource Tree question

Hi, Im trying to setup just a very simple site using a Resource Tree (some code below). The problem I'm having is getting the root / to render. so when i go to domain.com/ I get "No Such Resource No such child resource" The child nodes {terms,profile} are rendering fine. So looking at the resource tree and the main.py which holds the Main() Resource... how can I fix this issue. I have already tried setting isLeaf = True in Main() but that breaks terms and profile Cheers server.py ======================================= # resource tree root = Main() root.putChild('terms', Terms()) root.putChild('profile', Profile()) site = server.Site(root) reactor.listenTCP(6346, site) reactor.run() main.py ======================================= class IndexPage(Resource): def __init__(self): print "created new index page" Resource.__init__(self) def render_GET(self, request): print "rendering get" return "<html>INDEX PAGE</html>" class Main(Resource): def get_child(self, name, request): print "trying to get main" return IndexPage()

This probably isn't the proper way to do it, but it should work: root = resource.Resource() root.putChild('terms', Terms()) root.putChild('profile', Profile()) root.putChild('', IndexPage()) On Wed, Mar 14, 2012 at 5:46 AM, Lusana Ali <ali.lusana@gmail.com> wrote:
Hi,
Im trying to setup just a very simple site using a Resource Tree (some code below). The problem I'm having is getting the root / to render. so when i go to domain.com/ I get "No Such Resource No such child resource"
The child nodes {terms,profile} are rendering fine. So looking at the resource tree and the main.py which holds the Main() Resource... how can I fix this issue. I have already tried setting isLeaf = True in Main() but that breaks terms and profile
Cheers
server.py ======================================= # resource tree root = Main() root.putChild('terms', Terms()) root.putChild('profile', Profile())
site = server.Site(root) reactor.listenTCP(6346, site) reactor.run()
main.py ======================================= class IndexPage(Resource):
def __init__(self): print "created new index page" Resource.__init__(self)
def render_GET(self, request): print "rendering get" return "<html>INDEX PAGE</html>"
class Main(Resource):
def get_child(self, name, request): print "trying to get main" return IndexPage()
_______________________________________________ Twisted-Python mailing list Twisted-Python@twistedmatrix.com http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
-- Jasper

That worked a charm and I feel the fool for not having noticed that simple error =) Much appreciated! Lusana On Wed, Mar 14, 2012 at 9:16 PM, Enrique Samson Jr, <enriquejr@gmail.com> wrote:
On 03/14/2012 05:46 PM, Lusana Ali wrote:
class Main(Resource):
def get_child(self, name, request): print "trying to get main" return IndexPage()
Try changing get_child to getChild.
--Enrique
_______________________________________________ Twisted-Python mailing list Twisted-Python@twistedmatrix.com http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
participants (3)
-
Enrique Samson Jr,
-
Jasper St. Pierre
-
Lusana Ali