[Twisted-web] returning a formless form from render_foo

Donovan Preston dp at ulaluma.com
Mon Sep 6 14:47:15 MDT 2004


On Sep 5, 2004, at 1:42 AM, Tim Stebbing wrote:

> gday all,
>
> Im using nevow 0.2.0, ive got a simple formless resource that works
> fine when I view it alone, but when I return it from a render_ method,
> I get
>
>  nevow.compy.CannotAdapt: <redpanda.root.Index object at 0x4049796c>
> (type redpanda.root.Index) cannot be adapted to <class
> 'formless.iformless.IConfigurable'>.
>
> where redpanda.root.Index has:
>
> def render_foo(self, ctx, data):
>     return FooForm()
>
> Why is it trying to adapt the Index resource? whats the proper way to
> include a form resource in a templates output?

When you place renderForms('configurableName') in a page (the default  
value for configurableName is ''), Nevow does  
IConfigurable(ctx.locate(IConfigurableFactory).locateConfigurable('confi 
gurableName')). The default implementation of locateConfigurable when  
configurableName is '' simply returns "self".  This is why nevow is  
attempting to adapt your Index object to IConfigurable.

If in this case your FooForm is your configurable, I suggest making  
things explicit by implementing configurable_blarg on your Index Page,  
and using renderForms('blarg') instead of renderForms(). You could also  
override configurable_, but I think it is best to always think of the  
"canonical configurable" as the Page instance which is currently being  
rendered.

By the way, you can also have multiple configurables per Page by  
providing multiple configurable_ methods and using renderForms('foo')  
and renderForms('bar') to render the forms where you want them.

dp




More information about the Twisted-web mailing list