UnicodeDecodeError: 'ascii' codec can't decode byte 0xe3 in position 116: ordinal not in range(128)
どうやらテンプレートで日本語を使おうとしたときのunicodeのエンコード・デコードのエラーっぽい。
…
sentence = 'すもももももももものうち。'
template_values = {'sentence':sentence}
path = os.path.join(os.path.dirname(__file__), 'index.html')
self.response.out.write(template.render(path,template_values))
…
これのtemplate.render()に
.decode('utf-8')
をつけて
…
sentence = 'すもももももももものうち。'
template_values = {'sentence':sentence}
path = os.path.join(os.path.dirname(__file__), 'index.html')
self.response.out.write(template.render(path,template_values).decode('utf-8'))
…
となおしたら、大丈夫だった。テンプレートはutf-8で。
No comments:
Post a Comment