如何使用 Pylons / Mako 模板从独立的 python 脚本制作 HTML 电子邮件?

发布于 2024-10-07 02:33:01 字数 225 浏览 0 评论 0原文

我基本上是在问如何将 plyons 和 mako 文件“包含”在独立的 python 脚本中?

我有一个正在运行的网站,但我想做的是使用 Mako templatetes 来格式化我通过 cron 脚本启动的电子邮件。我想以这种方式重用尽可能多的代码,因为有时网站中的操作会生成电子邮件。

我可以让 cron 脚本访问某个 URL,然后使用 pylons 生成电子邮件,但该 hack 有许多明显的问题。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

时间海 2024-10-14 02:33:01

我没有使用 Pylons 的经验,但只需渲染一个模板即可。

from mako.template import Template

mytemplate = Template(filename='email.html')
sendemail("[email protected]", "[email protected]", mytemplate.render())

“独立”方法基本上是 Mako 与 CherryPy 等许多 WSGI 框架一起使用的方式。

Mako 文档

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("[email protected]", "[email protected]", mytemplate.render())

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

Mako Docs

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文