开发者

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜