当前位置: 首页>>代码示例>>Python>>正文


Python Template.decode方法代码示例

本文整理汇总了Python中tornado.template.Template.decode方法的典型用法代码示例。如果您正苦于以下问题:Python Template.decode方法的具体用法?Python Template.decode怎么用?Python Template.decode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在tornado.template.Template的用法示例。


在下文中一共展示了Template.decode方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: generate

# 需要导入模块: from tornado.template import Template [as 别名]
# 或者: from tornado.template.Template import decode [as 别名]
def generate(codes, output_path = './qrmaster',
             url='http://test.com', title='',
             img_path=None):
    """codes are tuples in the form: (code, id)"""
    
    module_path, _ = path.split(__file__)
    css_file_name = 'style.css'
    
    template_path = path.join(module_path, 'template.html')
    css_path = path.join(module_path, css_file_name)
    
    output_file = path.join(output_path, 'qrmaster.html')
    o_css_path = path.join(output_path, css_file_name)
    
    files_path = path.join(output_path, 'qrmaster')
    if not path.exists(files_path):
        makedirs(files_path)
    
    if img_path:
        _, img_file_name = path.split(img_path)
        o_img_path = path.join(output_path, img_file_name)
        copyfile(img_path, o_img_path)
    else:
        o_img_path = ''
    
    copyfile(css_path, o_css_path)
        
    data = []
    for c in codes:
        qr = qrcode.QRCode(
            version = 1,
            box_size = 5,
            border = 0,
            error_correction = 
                qrcode.constants.ERROR_CORRECT_H
        )
        full_url = urljoin(url, c[0])
        c.append(full_url)
        data.append(c)
        qr.add_data(full_url)
        qr.make()
        qr_path = path.join(files_path, c[0]+'.svg')
        qr.make_image(
            image_factory=qrcode.image.svg.SvgImage).save(
                qr_path)

    with open(template_path, 'r') as f:
        tmp = f.read()
        
    html = Template(tmp).generate(data=data,
                                  files_path=files_path,
                                  title=title,
                                  img_path=img_file_name)
    
    with open(output_file, 'w') as f:
        f.write(
            html.decode('utf-8')
        )
开发者ID:soulrevenges,项目名称:artificialAlan,代码行数:60,代码来源:generate.py


注:本文中的tornado.template.Template.decode方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。