简体   繁体   中英

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

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM