Vic*_*Yan 2 python django unicode google-app-engine
尝试在Google App Engine中呈现Django模板文件时
来自google.appengine.ext.webapp导入模板
templatepath = os.path.join(os.path.dirname(file),'template.html')
self.response.out.write(template.render(templatepath,template_values))
我遇到以下错误:
<type'exception.UnicodeDecodeError'>:'ascii'编解码器无法解码17692位的字节0xe2:序号不在范围内(128)
args =('ascii','<!DOCTYPE html PUBLIC" - // W3C // DTD XHTML 1.0海峡... 07/A-美丽-方法找到的和平的,心灵/ - >
",17692,17693, '在范围(128)')序数不
编码= 'ASCII'
端= 17693
message =''
object ='<!DOCTYPE html PUBLIC" - // W3C // DTD XHTML 1.0 Str ... 07/a-beautiful-method-to-find-peace-of-mind/ - >
reason ='序数不在范围内(128)'
start = 17692
似乎底层的django模板引擎已经采用了"ascii"编码,它应该是"utf-8".谁知道什么可能导致麻烦以及如何解决?谢谢.
好吧,结果是模板返回的渲染结果需要先解码:
self.response.out.write(template.render(templatepath,template_values).decode('utf-8'))
一个愚蠢的错误,但无论如何,谢谢大家的答案.:)
| 归档时间: |
|
| 查看次数: |
2358 次 |
| 最近记录: |