Django mysql arabic encoding

柔情痞子 提交于 2019-12-12 03:32:32

问题


I've a django app with a mysql database. We are trying to launch the Arabic version of the website. The current language is English. For some reason when I write something in Arabic through the admin panel and click save, it shows ???? instead of the Arabic word i wrote. I've no idea how to fix it.

I followed this post and added #-*- coding: utf-8 -*- to my admin.py, models.py and views.py files. It didn't work

I also added these to my.conf mysql file to change the character set. It didn't work either.

character-set-server=utf8
collation-server=utf8_unicode_ci
init_connect='set collation_connection = utf8_unicode_ci;'

回答1:


What probably happened:

  • you had utf8-encoded data (good)
  • SET NAMES latin1 was in effect (default, but wrong)
  • the column was declared CHARACTER SET latin1 (default, but wrong)

Please provide SHOW CREATE TABLE so we can formulate an ALTER to fix the columns.

Django needs client_encoding: 'UTF8'; sorry, I don't know where that goes.




回答2:


Did you checked encoding of your database and your tables? If they are not in utf-8, you might try to convert it.

ALTER DATABASE dbname CHARACTER SET utf8 COLLATE utf8_general_ci;
ALTER TABLE tablename CHARACTER SET utf8 COLLATE utf8_general_ci;
ALTER TABLE `db_table_name` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci

(code is from here: Save Data in Arabic in MySQL database)



来源:https://stackoverflow.com/questions/35522102/django-mysql-arabic-encoding

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