On Wed, Jul 16, 2008 at 11:56 AM, Christoph Haas
<[EMAIL PROTECTED]> wrote:
> Dear list,
>
> we are trying to use the "render()" function from within websetup.py.
> Actually it's not exactly websetup.py but a batch script that is derived
> from websetup.py. We want to send emails from that script and thought that
> it might be nice to use Mako templates for that purpose. Unfortunately
> things aren't as simple as we thought.
>
> Our script:
>
> ============================================================
> # -*- coding: utf-8 -*-
> # render test in pylons context
>
> filename='/path/to/development.ini'
>
> from paste.deploy import appconfig
> from pylons import config
> from pylons.templating import render
> from debexpo.config.environment import load_environment
>
> conf = appconfig('config:' + filename)
> load_environment(conf.global_conf, conf.local_conf)
>
> print render('/email/changes_list.mako')
> ============================================================
>
> Unfortunately this fails with:
>
> ============================================================
> python bin/render.py
> Traceback (most recent call last):
>  File "bin/render.py", line 14, in <module>
>    print render('/email/changes_list.mako')
>  File "/var/lib/python-support/python2.5/pylons/templating.py", line 343,
> in render
>    return pylons.buffet.render(template_name=template, fragment=fragment,
>  File "/var/lib/python-support/python2.5/paste/registry.py", line 137, in
> __getattr__
>    return getattr(self._current_obj(), attr)
>  File "/var/lib/python-support/python2.5/paste/registry.py", line 194, in
> _current_obj
>    'thread' % self.____name__)
> TypeError: No object (name: Buffet) has been registered for this thread
> ============================================================

It would be easiest to just render the templates natively in Mako
rather than trying to use render.  Buffet is tied really closely to
Pylons and entry points, which means you have to have the exact right
environment configured in order to use it.  Buffet is also deprecated
in Pylons 0.9.7-beta, so it's not worth spending time trying to get it
to work.

Your best bet is to create a Mako template loader as described in the
Mako manual, passing it the template directory (myapp/templates) and
cache directory (myapp/data/templates).

For template variables, it's easiest to put them in a dict and pass
that to Mako's render method.  You could also try using pylons.c and
the render_mako function in Pylons 0.9.7-beta.

-- 
Mike Orr <[EMAIL PROTECTED]>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"pylons-discuss" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to