原文链接: https://hsiaofeng.com/archives/185.html
原代码
with open(f"file.j2",'w+') as fout:
content = template.render()
fout.write(content)
解决方案
将 open()
处的 w+
改为 wb
,在 template.render()
后调用 encode('utf-8')
。
with open(f"file.j2",'wb') as fout:
content = template.render().encode('utf-8')
fout.write(content)
本文转自: https://hsiaofeng.com/archives/185.html
本站仅做收录,版权归原作者所有。