4

I'm basically asking how to "include" the plyons and mako files in a stand alone python script?

I have a working web site, but what I want to do is use Mako templetes to format emails that I initiate through a cron script. I want to do it this way to reuse as much code as possible, as sometimes actions in the web site generate emails.

I could make the cron script access a certain URL, and then use pylons to generate the email, but that hack has many obvious problems.

BoltClock
  • 700,868
  • 160
  • 1,392
  • 1,356
Tom
  • 43
  • 3

1 Answers1

4

I have no experience with Pylons but to just render a template you can

from mako.template import Template

mytemplate = Template(filename='email.html')
sendemail("text@example.com", "me@example.com", mytemplate.render())

The "standalone" approach is basically the way Mako gets used with a lot of WSGI frameworks like CherryPy.

Mako Docs

Novikov
  • 4,399
  • 3
  • 28
  • 36
  • 1
    Thanks. That works great. Also, just a FYI to others, can pass variables into render as named variables. That is mytemplate.render(c=my_var) this will have my_var be visable in the template as c – Tom Dec 11 '10 at 03:37