python – Mako模板中的UnicodeEncodeError
发布时间:2020-12-20 11:16:21 所属栏目:Python 来源:网络整理
导读:我有以下文件 dummy.py #!c:/Python27/python.exe -ufrom mako import exceptionsfrom mako.template import Templateprint "Content-type: text/html"print#VARIABLE = "WE" VARIABLE = "我们"template = Template(filename='../template/dummy.html',outpu
我有以下文件
dummy.py #!c:/Python27/python.exe -u from mako import exceptions from mako.template import Template print "Content-type: text/html" print #VARIABLE = "WE" VARIABLE = "我们" template = Template(filename='../template/dummy.html',output_encoding='utf8') try: print template.render(VARIABLE=VARIABLE) except: print exceptions.html_error_template().render() dummy.html(以UTF-8格式保存) hello world 哈罗世界 ${VARIABLE} 我已经审阅了http://www.makotemplates.org/docs/unicode.html的指令 但是,我仍然得到错误
我错过了什么? 解决方法template = Template(filename='../template/dummy.html',default_filters=['decode.utf8'],input_encoding='utf-8',output_encoding='utf-8') (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |