简单HTML生成器

PyHTML的Python项目详细描述


https://travis-ci.org/cenkalti/pyhtml.svg?branch=masterhttps://coveralls.io/repos/github/cenkalti/pyhtml/badge.svg?branch=master

pyhtml是一个简单的python html生成库。

灵感来自Flask-HTMLBuilderthis gist

功能

  • 与Python2和3兼容
  • 输出缩进良好的代码
  • 有些标记具有合理的默认值
  • 以后用块填充

安装

$ pip install pyhtml

文档

请参阅pyhtml.py文件上的docstring。

示例

frompyhtmlimport*deff_links(ctx):fortitle,pagein[('Home','/home.html'),('Login','/login.html')]:yieldli(a(href=page)(title))t=html(head(title('Awesome website'),script(src="http://path.to/script.js")),body(header(img(src='/path/to/logo.png'),nav(ul(f_links))),div(lambdactx:"Hello %s"%ctx.get('user','Guest'),'Content here'),footer(hr,'Copyright 2013')))printt.render(user='Cenk')

以上代码呈现为:

<!DOCTYPE html><html><head><title>
      Awesome website
    </title><scriptsrc="http://path.to/script.js"type="text/javascript"></script></head><body><header><imgsrc="/path/to/logo.png"/><nav><ul><li><ahref="/home.html">
              Home
            </a></li><li><ahref="/login.html">
              Login
            </a></li></ul></nav></header><div>
      Hello Cenk
      Content here
    </div><footer><hr/>
      Copyright 2013
    </footer></body></html>

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
值为ArrayList的java ConcurrentHashMap   使用SpringRESTTemplate的java Post多部分(PDF)文件   如果数据太小,Java刷新进程的输出流不会立即发送数据   游戏物理Java:玩家移动错误   java使用小型数据类型是否会减少内存使用(从内存分配而不是效率)?   java如何在SeleniumWeb驱动程序的类属性中验证映像   java使用Maven汇编插件设置Linux文件权限,即使在其他平台上运行?   java我需要在一个对象中保存一个mp4文件,以便将其存储在链接列表中。可能吗?   java删除组织中的重复项。dom4j。文档对象   java组织。冬眠LazyInitializationException:无法初始化没有会话5的代理   java使用JFileChooser允许Swing用户指定输出位置   java JFreeChart,如何重新缩放yaxis   java响应头GAE端点   java安卓:更改视图大小