How to use Pylons / Mako templates to make an HTML email from a stand alone python script?

StackOverflow https://stackoverflow.com/questions/4405066

  •  25-09-2019
  •  | 
  •  

Question

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.

Was it helpful?

Solution

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top