civilvar 发表于 2017-4-23 10:19:32

python模板比较

django-template ,代码写起来很美观,但是太弱了。

mako , 小强,小而强大,编译为python代码,性能优异。但就是 % for% if 的语法感觉很奇怪, block的用法也比较不同,不习惯。

jinja , 正在看,从设计初衷上看,它的目标是替换django-template ,拥有和django-template 极其相似的风格,并且更加强大。

Cheetah ,他的语法我不太喜欢,非tag式的。代码凌乱。

Genshi 引用一段话

引用
genshi 刚成取代 kid 之势,看来 myghty 就快要被 mako 取代了,呵呵。
genshi/kid 的特点在于方便灵活的 xml 生成;mako/myghty 是用来生成任意形式的模版的,特点在于将 python 语言优雅地植入到模版中,并且将模版编译成 python 代码,获得极高的性能。
而这两组中的前者都超越了后者一大步!难道 genshi 和 mako 要平分(django以外的)模版世界了?拭目以待。
另外由于 mako 将模版查找的逻辑抽象到灵活的 TemplateLookup 里面 (窃以为是学习了 django 模版的思想),我想在要在 django 的基于 app 的架构中应用 mako 模版应该不是难事,有机会要尝试一下。
再另外 mako 模版还吸收了 django 模版中的 filter 的概念。


引用,mako 主页上的性能测试。

引用
Insanely Fast. An included bench suite, adapted from a suite included with Genshi, has these results for a simple three-sectioned layout:
Mako:1.10 ms
Cheetah:1.10 ms
Django:2.74 ms
Myghty:4.52 ms
Genshi:11.46 ms
Kid:14.54 ms

Since a speed test is always a flashpoint for controversy, and you can modify the bench to show different variances, the point here is not that "Mako is faster"; its not meant as a competitive point. The point is, "Mako is as fast as any of the other currently popular approaches".


综合来看,我觉得jinja,这个小日本开发的模板语言是django开发最好的选择
页: [1]
查看完整版本: python模板比较