I have a legacy database with Latin 1 encoding. I do not have the access to convert it to utf8 when I read value from the model I am getting distorted text.
I tried to use name.decode ('utf-8') but it is throwing a Unicode error:
< Code> 'ascii' can not encode characters in codec position 4-12: not in sorted range (128)name.encode ('utf-8') either does not work Does.
If you have access to your 'settings.py' file, you can say that Your database is using 'latin1'.
The following is an example of the 'database' configuration in the 'settings.py' file.
DATABASES = {'default': '' engine ':' django.db.backends.mysql ',' NAME ':' test_db ',' USER ':' root ',' password '', 'HOST': '', 'PORT': '3306', 'Option': {'charset': 'Latin 1', 'use_onikoda': true,},},} / Pre>
I had a similar problem, check the link here
No comments:
Post a Comment