[Twisted-web] How to nest LiveElements? (getting a MissingRenderMethod error)

Jean-Paul Calderone exarkun at divmod.com
Fri Dec 1 09:52:32 CST 2006


On Fri, 1 Dec 2006 16:49:49 +0200, kgi <iacovou at gmail.com> wrote:
>On Friday 01 December 2006 16:20, Jean-Paul Calderone wrote:
>> On Fri, 1 Dec 2006 15:35:34 +0200, kgi <iacovou at gmail.com> wrote:
>> All Element renderers _must_ use renderer().  All Fragment/Page renderers
>> _must_ use the "render_" prefix.  All Athena callables _must_ use expose().
>>
>> No other approach will work at all.
>
>Hi JP; thanks for your reply. That has got it working!
>
>Can I ask, what's the high-level, hand-wavey, fuzzy-feeling distinction
>between a Page and an Element?

A more accurate parallel to draw is one between Fragment and Element.  Page
is the top dog for now: it is the IResource implementation in Nevow, and you
have to have an IResource implementation as the very base component involved
in rendering a page.  Since the renderers on a Page can return either
Fragments or Elements, you can then construct the rest of your page out of
a collection of other classes (as I'm sure you well know :).

The difference between Fragment and Element is just this: Fragment renderers
are passed a context, Element renderers are not.

This is the first step in a long process of eliminating the context from
Nevow.  At some very distant time (years hence, likely), Page and Fragment
will be removed, to be replaced by classes which present APIs which do not
involve the context.  Right now, there is no substitute for Page, but
Element is the substitute for Fragment.

The difference in the way render methods are dispatched between Fragment and
Element is somewhat incidental to this.  At some future time, it may be
possible to customize Element so that it also dispatches to render_, since
this isn't really an essential part of the change Element actually exists to
facilitate.

> [snip]
>
>> >   from nevow.page import renderer
>> >   def innerWidget ( self, request, tag ):
>> >        ...
>> >        return elem
>> >   renderer(innerWidget)
>>
>> Like the other examples, you could return ctx.tag[elem] here.
>
>Do you mean, tag[elem], since these render methods receive (request,tag)
>rather than (ctx,data)?

Oops!  Yes, exactly that. :)

Jean-Paul



More information about the Twisted-web mailing list