Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我基本上是在问如何在独立的 python 脚本中“包含” plyons 和 mako 文件?
我有一个工作网站,但我想做的是使用 Mako 模板来格式化我通过 cron 脚本启动的电子邮件。我想这样做以尽可能多地重用代码,因为有时网站中的操作会生成电子邮件。
我可以让 cron 脚本访问某个 URL,然后使用 pylons 生成电子邮件,但是这种 hack 有很多明显的问题。
我没有使用 Pylons 的经验,但只是渲染一个模板,你可以
from mako.template import Template mytemplate = Template(filename='email.html') sendemail("text@example.com", "me@example.com", mytemplate.render())
“独立”方法基本上是 Mako 与许多 WSGI 框架(如 CherryPy)一起使用的方式。
Mako 文档