github地址

http://mustache.github.io/
https://github.com/defunkt/pystache

使用:

  1. >>> import pystache
  2. >>> print pystache.render('Hi {{person}}!', {'person': 'Mom'})
  3. Hi Mom!

has为boolean值时,true则中间的逻辑执行,false则不执行

  1. >>>print(pystache.render("hello {{name}} {{#has}} world {{value}} {{/has}}",
  2. {"name": "tingjio",
  3. "has": False,
  4. "value": "mengsio"}))
  5. hello tingjio
  6. >>>print(pystache.render("hello {{name}} {{#has}} world {{value}} {{/has}}",
  7. {"name": "tingjio",
  8. "has": True,
  9. "value": "mengsio"}))
  10. hello tingjio world mengsio

has是数组时,循环获取数组的值

  1. >>> print(pystache.render("hello {{name}} {{#has}} world {{child}} " "{{/has}}",
  2. {"name": "tingjio",
  3. "has": [{"child": '1'},
  4. {"child": '2'},
  5. {"child": '3'},
  6. ],
  7. "value": "mengsio"}
  8. ))
  9. hello tingjio world 1 world 2 world 3