本文整理汇总了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')
)