python -- Django 乱码问题解决方案
时间:2014-12-02 13:10 来源:linux.it.net.cn 作者:IT
乱码问题
1,插入数据库乱码,文件前加入
[python]view plaincopyprint?
-
import sys
-
reload(sys)
-
sys.setdefaultencoding('utf8')
同时保证数据库接口是utf8的
[sql]view plaincopyprint?
-
mysql> alter database databasename default character set utf8 collate utf8_general_ci;
-
mysql>alter table tablename default character set utf8 collate utf8_general_ci;
当然有时候也要用
[sql]view plaincopyprint?
-
mysql>set names 'utf8'
对于已经建好的表用
[sql]view plaincopyprint?
-
alter table tablename convert to character set utf8
否则会出现类似
Incorrect string value: '\xE6\x9B\xB9\xE5\x86\xAC...' for column 'realname' at row 1 的问题
(责任编辑:IT)
乱码问题 1,插入数据库乱码,文件前加入
[python]view plaincopyprint?
同时保证数据库接口是utf8的
[sql]view plaincopyprint?
当然有时候也要用
[sql]view plaincopyprint?
对于已经建好的表用
[sql]view plaincopyprint?
否则会出现类似
Incorrect string value: '\xE6\x9B\xB9\xE5\x86\xAC...' for column 'realname' at row 1 的问题(责任编辑:IT) |