write html-headers (utf-8)
"Martin v. Löwis"
martin at v.loewis.de
Mon May 30 03:46:14 EDT 2005
db wrote:
> In this template I write a few Mysql variables.
> Those variable often have german characters. This characters (Gösing in
> stead of Gösing). The german characters in the html template are shown
> correctly.
The problem is then with these variables: apparently, the Mysql
variables are encoded in iso-8859-15, and you need to recode them
to UTF-8 first before putting them into the template.
var = var.decode("iso-8859-15").encode("utf-8")
> As you can see, I put in the header of the html template that the encoding
> is UTF-8, the browser still shows windows ISO-8859-15. Can I write the
> header with python so the browser uses the utf-8 encoding?
The problem is not the header, but the body. The browser sees your claim
that the page is UTF-8, but doesn't believe it. This is because it tries
to interpret the page as UTF-8, and then finds invalid byte sequences
(your latin-9 characters), and then knows that the page *can't* be
UTF-8. It then guesses that the page must be latin-something. That guess
is wrong, of course, also, because some characters in the page are
utf-8, and others latin-9. This is invalid HTML.
Regards,
Martin
More information about the Python-list
mailing list