3

私は次のファイルを持っています

ダミー.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()

ダミー.html(UTF-8形式で保存)

hello world
哈罗世界
${VARIABLE}

http://www.makotemplates.org/docs/unicode.htmlからの指示を参照しました

ただし、それでもエラーが発生します

UnicodeDecodeError:'ascii'コーデックは位置0のバイト0xe6をデコードできません:序数が範囲内にありません(128)

私が見逃したものはありますか?

4

2 に答える 2

6
template = Template(filename='../template/dummy.html', default_filters=['decode.utf8'], input_encoding='utf-8', output_encoding='utf-8')
于 2010-12-22T05:25:11.527 に答える
2

はい、ASCIIにレンダリングしようとしているため、機能しません。使用するoutput_encodingを指定する必要があります。

Template(filename='../template/dummy.html', output_encoding='utf8')

そして、むき出しの以外は持ってはいけません。キャッチすると予想される例外を追加します。

于 2010-12-21T09:07:04.957 に答える