[Twisted-web] Nevow: directive("header")
Mary Gardiner
twisted-web@twistedmatrix.com
Sat, 20 Mar 2004 19:11:50 +1100
--a8Wt8u1KmwUX3Y2C
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Hi,
I've been learned Nevow mainly by instinct, so this may be documented
somewhere and I can't find it.
If I wanted to produce XML that looks something like:
<tag1>
<tag2/>
<tag3/>
<tag4/>
<tag4/>
...
<tag4/>
</tag1>
how would I do it?
I am using render = directive("sequence") for tag1, and pattern = "item"
for tag4.
This works fine for:
<tag1>
<tag4/>
<tag4/>
...
<tag4/>
</tag1>
but I want to include those extra tags. I thought setting render =
directive("heading") on tag2 and tag3 might work, but it gives the
following error:
File "/home/mary/src/Nevow/nevow/accessors.py", line 53, in child
return self.original[int(name)]
exceptions.ValueError: invalid literal for int(): header
after a long traceback.
The two attached files should demonstrate the problem: noheader.py
works, header.py gives the error mentioned.
Is this a bug or am I simply going about this the wrong way?
-Mary
--a8Wt8u1KmwUX3Y2C
Content-Type: text/x-python; charset=us-ascii
Content-Disposition: attachment; filename="noheader.py"
from nevow import rend, stan, tags, appserver
from twisted.application import service, internet
class TestHeader(rend.Page):
def data_list(self, context, data):
return ["item 1", "item 2", "item 3"]
def data_header(self, context, data):
return "header"
def render_plain(self, context, data):
return context.tag[data]
docFactory = rend.stan(tags.html[
tags.body(render = stan.directive("sequence"), data = stan.directive("list"))[
tags.p(pattern = "item", render = stan.directive("plain"))
]
])
application = service.Application("Header pattern test")
internet.TCPServer(
8080,
appserver.NevowSite(
TestHeader()
)
).setServiceParent(application)
--a8Wt8u1KmwUX3Y2C
Content-Type: text/x-python; charset=us-ascii
Content-Disposition: attachment; filename="header.py"
from nevow import rend, stan, tags, appserver
from twisted.application import service, internet
class TestHeader(rend.Page):
def data_list(self, context, data):
return ["item 1", "item 2", "item 3"]
def data_header(self, context, data):
return "header"
def render_plain(self, context, data):
return context.tag[data]
docFactory = rend.stan(tags.html[
tags.body(render = stan.directive("sequence"), data = stan.directive("list"))[
tags.h1(data = stan.directive("header"), pattern = "header"),
tags.p(pattern = "item", render = stan.directive("plain"))
]
])
application = service.Application("Header pattern test")
internet.TCPServer(
8080,
appserver.NevowSite(
TestHeader()
)
).setServiceParent(application)
--a8Wt8u1KmwUX3Y2C--