Django character latin1 mysql

我只是一个虾纸丫 提交于 2019-11-28 05:58:36

问题


I create a django application with existing MySQL database, the problem is the encoding to database is latin1_general_c and the utf8 characters is save like this ñ => ñ , ó => ó, i need present the information in that page in correctly form but django show the information of database like this

recepción, 4 oficinas, 2 baños

i need show like this

recepcíon, 4 oficinas, 2 baños

For many reasons I can't change the database to utf8

what do I do for show information the correctly way?


回答1:


Django seems to explicitly require that your database use UTF-8:

Django assumes that all databases use UTF-8 encoding. Using other encodings may result in unexpected behavior.

That said, it should be possible to use the custom OPTIONS setting to pass the desired character set to the database driver. See this answer, in which setting charset solved the problem. But you should check the documentation for the specific MySQL driver and database that you're using, since these options are not used by Django itself.

As suggested by the quote above, even if this works to correctly translate strings between the database and unicode, parts of Django still won't work correctly. For example, to correctly validate the length of a CharField Django has to know the encoding, and it will always assume UTF-8.



来源:https://stackoverflow.com/questions/28523138/django-character-latin1-mysql

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!