UnicodeDecodeError:'ascii'编解码器无法解码字节0xc5

Har*_*šić 7 python mod-wsgi mako python-2.7

UnicodeDecodeError: 'ascii' codec can't decode byte 0xc5 in position 537: ordinal not in range(128), referer: ...
Run Code Online (Sandbox Code Playgroud)

当我尝试使用字符"č"输出整个网站时,我总是收到此错误.我正在使用mako模板.该怎么办?

Ant*_*ala 9

发生错误是因为某处代码将您的unicode模板字符串强制转换为python 2 str; 您需要自己将渲染的模板编码为UTF-8字节串:

if isinstance(rendered, unicode):
    rendered = rendered.encode('UTF-8')

# rendered is now guaranteed to be of type str
Run Code Online (Sandbox Code Playgroud)