[Grok-dev] Re: RFC: In-class template definition in grok.View

Darryl Cousins darryl at darrylcousins.net.nz
Thu May 3 04:01:35 EDT 2007


Hi,

On Tue, 2007-05-01 at 13:10 +0200, Martijn Faassen wrote:
> kevin at mcweekly.com wrote:
> > Quoting Darryl Cousins <darryl.cousins at treefernwebservices.co.nz>:
> [snip Darryll's reply and Kevin's response]
> 
> I think Darryl's reply isn't showing up on the mailing list for some reason.

Wrong ReplyTo address, human error. My original reply is pasted below:

Hi Kevin,

I tried playing around with this and importing templates and I found
that we can do this:

shared.py::

def template_factory():
    template = grok.PageTemplateFile(os.path.join('template.pt'))
    return template()

app.py::
[snip imports and Model class]

class MyView(grok.View):
    def render(self):
        return shared.template_factory()

template_factory could all sorts of useful stuff with request and
context before choosing and returning the pagetemplate.

BTW This works as per your last example:

class Index(grok.View):
    """<html><body>
    <p>ME GROK HELLO WORLD!</p>
    </body></html>"""
    pass

index = grok.PageTemplate(Index.__doc__)

But I couldn't get any kind of combination of:

index = share.template_factory to work

including playing with template_factory method or directly calling a
page template:

template_factory = grok.PageTemplateFile(os.path.join('template.pt'))

for example.


Best regards,
Darryl




More information about the Grok-dev mailing list