if __name__ == '__main__':
#context = {}
try:
logging.basicConfig(filename='myapp.log',level=logging.DEBUG)
tpl=DocxTemplate('report-tpl.docx')
print(context)
jinja_env = jinja2.Environment(autoescape=True)
tpl.render(context, jinja_env)
tpl.save(context['output_name'])
print('success')
except jinja2.exceptions.TemplateError as e:
print(list(e.docx_context))
print(e.lineno)
except Exception as e:
print(e)
docxtpl 捕获jinja2.exceptions.TemplateError 调试模板错误
最新推荐文章于 2024-02-20 15:37:58 发布