%}
{{ novel.title }}
{% endfor %}
如果不加任何转换,页面上显示的中文将会是字节码
10;"
result = mysql.getAll(sql)
for each in result:
ach['title'] = each['title'].decode('utf-8')
字符串通过编码转换为字节码
,字节码通过解码转换为字符串:
str--->(encode)--->bytes,bytes--->(decode)--->str
decode和encode详解
decode 解码,在已知字符串编码的情况下
ensure_ascii
如果无任何配置,或者说使用默认配置, 输出的会是中文的ASCII字符吗,而不是真正的中文。 这是因为json.dumps 序列化时对中文默认使用的ascii编码。
python3中存在序列化问题:
TypeError: Object of type bytes is not JSON serializable
小结
在Web开发中,这个问题真的很讨厌,中文编码来回转换