[Grok-dev] Re: Getting a view from within a REST layer

Jan-Wijbrand Kolman janwijbrand at gmail.com
Mon Dec 10 15:20:49 EST 2007


Hi Peter,

Peter Bengtsson wrote:
> getMultiAdapter((context, request), name="Nameofview")
> doesn't work inside my REST layer which I built thanks to this tutorial:
> http://grok.zope.org/minitutorials/rest.html
> 
> This is the error I get:
>     raise ComponentLookupError(objects, interface, name)
> ComponentLookupError: ((<snapatom.app.snapatom object at 0x8b7f6ac>,
> <InterfaceClass zope.interface.Interface>), <InterfaceClass
> zope.interface.Interface>, 'bloglist')

snip

> Am I doing it completely wrong or is it a bug?
> I basically want to render a view and spit out its result in the method
> GET() of my REST layer.

The thing I do not really understand about the error message you get is,
that getMultiAdapter() is looking for a component adapting the
combination of <snapatom.app.snapatom> and <zope.interface.Interface>...
somehow the request object you obtain seems not to provide any useful
interface for the lookup.

A wild guess, but what happens if you do:

  from zope.interface import alsoProvides

  class MyREST(grok.REST):
    grok.layer(AtomPubLayer)
    grok.context(snapatom)

    def GET(self):
        # ugly hack to test the lookup
	alsoProvides(request, IBrowserRequest)
        view = getMultiAdapter((context, request), name="bloglist")
        return view()

Mind though, even if this does work, it is basically "lying" to the
component system - I would have guessed too that the request object you
get in the REST context could be used for view lookups. But the REST
stuff is a bit misty to me...


HTH
kind regards,
jw



More information about the Grok-dev mailing list