kravb
kravb

Reputation: 558

UTF-8 string not displaying character properly

I am returning text field from DB column:

 "algún nombre de juego"

when I try to use this text in an html file, I get the following string:

algún nombre de juego

This happens consistently with any string that is not pure english. I have even tried grabbing simple text from online in different languages and as soon as I plug them into an html text box, the print out with improper encoding like the example above.

From reading Unicode documentation for python, UTF-8 should be able to handle pretty much any character in any language.

I have tried many ways of encoding/decoding, and either there is an encoding error, or I get back weird character where the letter u with acute should be.

Per comments, I am not using Django or Flask. Just taking strings from a DB that might be in several different languages and generating an HTML file for internal use.

Upvotes: 0

Views: 441

Answers (1)

Llamax
Llamax

Reputation: 337

A few ideas:

1. Remember to declare the encoding. Either:

  • Insert a <meta charset="utf-8"> just after your <head> tag.

    OR

  • do this in the HTTP header (making it look something like Content-Type:text/html; charset=UTF-8). This can be done by changing the webserver's settings or using server-side code, should you choose to host the page.

2. Ensure that your IDE saves files as UTF-8. This will be somewhere in your settings and should be done automatically, but worth checking if option 1 doesn't work.

Hope one of these works.

Upvotes: 1

Related Questions