[Flask] Displaying Chinese characters
CCP Dragonedge
ccp at drsb.com.my
Fri Jun 5 05:31:36 EDT 2020
Hi,
Does anyone have any experience dealing with Chinese characters? In my
code, I set a string to Chinese characters:
s = [some Chinese characters]
At first, Flask choked. So, at the very top of my code, I put:
# -*- coding: utf-8 -*-
That solved the problem. I could display the string in my templates by just
doing {{ s }}.
Here's the weird problem. If I write the Chinese characters directly in the
template, like so:
<!-- this works -->
<p>{{ s }}</p>
<!-- this doesn't -->
<p> [Chinese characters written directly with my editor]</p>
The browser (Edge) displays the following error:
'utf-8' codec can't decode byte 0xb5 in position 516: invalid start byte
I tried putting the following at in the HTML:
<head>
<meta charset="utf-8">
</head>
But that doesn't help. Why can Jinja decode it, but not the browser?
Thanks,
p
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/flask/attachments/20200605/dc6ad15b/attachment.html>
More information about the Flask
mailing list