python 的轻量级模板引擎
这是 Python 中最简单、轻量级的 html 模板引擎,我可以用它来生成定制的电子邮件通讯。
Which is the simplest and light weight html templating engine in Python which I can use to generate customized email newsletters.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
string.Template 有什么问题吗?这是标准 Python 发行版,并由 PEP 292 涵盖:
Anything wrong with string.Template? This is in the standard Python distribution and covered by PEP 292:
对于一个非常小的模板任务,Python 本身并没有那么糟糕。示例:
从这个意义上说,您可以在 Python 中使用字符串格式来进行简单的模板化。这就是它所能达到的最轻量。
如果你想更深入一点,Jinja2 是最“设计者友好”(读作:简单)的模板引擎在许多人看来。
您还可以查看 Mako 和 Genshi。最终,选择权在您(具有您想要的功能并与您的系统完美集成)。
For a really minor templating task, Python itself isn't that bad. Example:
In this sense, you can use string formatting in Python for simple templating. That's about as lightweight as it gets.
If you want to go a bit deeper, Jinja2 is the most "designer friendly" (read: simple) templating engine in the opinion of many.
You can also look into Mako and Genshi. Ultimately, the choice is yours (what has the features you'd like and integrates nicely with your system).
在Google中搜索tiny template Python发现了Titen,其源代码仅为5.5 kB。 Titen 可以对列表进行迭代,而内置的 str.format 则不能。
Mako 声称是轻量级的,但与 Titen 相比,它相对较胖(>200 kB)。 Jinja2 和 Django 模板也远超过 100 kB。
Searching for tiny template Python in Google turned up Titen, whose source code is only 5.5 kB. Titen can do iteration over lists, which the built-in str.format can't.
Mako claims to be lightweight, but it's relatively fat (>200 kB) compared to Titen. Jinja2 and Django Templates are also well over 100 kB.
尝试一下 python-micro-template:
https://github.com/diyism/python-micro -template
使用示例(kivy):
模板示例(kvml):
Give a try to python-micro-template:
https://github.com/diyism/python-micro-template
Usage example(kivy):
Template example(kvml):