Skip to main content

Generate documents according to the template.

Project description


使用 pip 安装:

pip install document-template


参考 test.pytest.html :

    <meta charset="UTF-8">
    <meta name="viewport"
        content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
<a href="#{url}">#{url}</a>
<span style="font-size: larger;font-weight: bold">#{large_font}</span>
为真时显示:#{bool:show_span}<span>显示的内容</span>#{bool:show_span};;分割;;#{bool:show_span}show_span is True#{bool:show_span}
#{copy:start}多行文字,替换局部内容:#{contents} 和 #{another_contents}#{copy:end}
from document_template import DocumentTemplate

if __name__ == '__main__':
    id_dict = {"title": "标题", "head": "正文标题", "url": "", "large_font": "大号字体"}
    id_dict['show_span'] = True

    # Multi-line copy supports string, list and tuple
    # id_dict['contents'] = 'ABCDEFG'
    # id_dict['another_contents'] = '1234567'
    id_dict['contents'] = ('A', 'B', 'C', 'D', 'E', 'F', 'G')
    id_dict['another_contents'] = ['1', '2', '3', '4', '5', '6', '7']
    temp = DocumentTemplate()
    temp.load("test.html", encoding='utf-8')
    temp.linefeed = '<br>\n'


  • 成对出现的 #{bool:} 须在同一行;
  • 成对出现的 #{copy:} 须在同一行;
  • 不支持 #{bool:}#{copy:} 嵌套使用。


  • 支持 Python 3;
  • 支持多行拷贝中有多个 #{标识符}
  • 支持自定义多行拷贝的换行符。


MIT License

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for document-template, version 0.0.6
Filename, size File type Python version Upload date Hashes
Filename, size document_template-0.0.6-py2.py3-none-any.whl (4.4 kB) File type Wheel Python version py2.py3 Upload date Hashes View
Filename, size document-template-0.0.6.tar.gz (4.9 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page