zoukankan      html  css  js  c++  java
  • python template engine

    Tenjin

      a fast and full-featured template engine based on embedded Python.

    install:

      sudo easy_install Tenjin

    example:

    ## views/example.pyhtml
        <?py #@ARGS title, items ?>
        <h2>${title}</h2>
        <table>
          <?py cycle = new_cycle('odd', 'even') ?>
          <?py for item in items: ?>
          <tr class="${cycle()}">
            <td>${item}</td>
          </tr>
          <?py #endfor ?>
        </table>

        ## main.py
        import tenjin
        #tenjin.set_template_encoding('utf-8')  # optional (default 'utf-8')
        from tenjin.helpers import *
        from tenjin.html import *
        engine = tenjin.Engine(path=['views'])
        context = {'title': 'Example', 'items': ['Haruhi', 'Mikuru', 'Yuki'] }
        output = engine.render('example.pyhtml', context)
        print(output)

        ## output
        $ python main.py
        <h2>Example</h2>
        <table>
          <tr class="odd">
            <td>Haruhi</td>
          </tr>
          <tr class="even">
            <td>Mikuru</td>
          </tr>
          <tr class="odd">
            <td>Yuki</td>
          </tr>
        </table>

    download:

    http://www.kuwata-lab.com/tenjin/

  • 相关阅读:
    Jemter---基础概念
    Jmeter---线程操作
    性能接口面试题
    Linux---网络命令
    测试所用链接地址
    Linux---压缩解压命令
    Linux----用户管理命令
    性能面试题
    Linux---帮助命令
    Linux--文件搜索命令
  • 原文地址:https://www.cnblogs.com/Mingxx/p/1961357.html
Copyright © 2011-2022 走看看