[Twisted-web] Trouble with templates

Jason Mobarak jason.mobarak at gmail.com
Wed Jun 30 22:30:28 MDT 2004


"""
I'm having trouble with templates and slots... this example code is
producing a traceback, am I doing something wrong?
"""

from twisted.application import service
from twisted.application import internet

from nevow import appserver, loaders, rend, tags, inevow
from formless import annotate, webform, iformless

xml0 = loaders.xmlstr("""<?xml version="1.0"?>
<html xmlns:n="http://nevow.com/ns/nevow/0.1">
<body>
<div n:render="sequence" n:data="foo">
<p n:render="sequence" n:pattern="item">
<span n:pattern="item" n:render="string" />
<span n:pattern="item" n:render="string" />
<div n:pattern="footer" n:render="bar">
<n:slot name="bar" />
</div>
</p>
</div>
</body>
</html>
""")

xml1 = loaders.xmlstr("""<?xml version="1.0"?>
<p xmlns:n="http://nevow.com/ns/nevow/0.1" n:data="baz" n:render="string" />
""")


class FooPage (rend.Page):

    docFactory = xml0

    def data_foo (self, ctx, d):

        return [['foo ', ' bar'], ['oof ', ' rab']]

    def render_bar (self, ctx, d):

        ctx.fillSlots('bar', xml1)
        return ctx.tag

    def data_baz (self, ctx, d):

        return "baz"
        

application = service.Application("MinimalExample")
server = internet.TCPServer(8080, appserver.NevowSite(FooPage()))
server.setServiceParent(application)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: minimalex.tac
Type: application/octet-stream
Size: 1164 bytes
Desc: not available
Url : http://pyramid.twistedmatrix.com/pipermail/twisted-web/attachments/20040630/bed7dc3b/minimalex.obj


More information about the Twisted-web mailing list