在使用DJANGO做WEB框架,用MySQLdb连接mysql数据库时,插入中文报以下错误 :

'latin-1' codec can't encode characters in position 59-60: ordinal not in range(256)


在游标中设置字符集不起作用

cur.execute('set names utf8')

需要在连接时就进行设置

MySQLdb.connect(self.db_address,self.db_user,self.db_password,self.db_name,charset='utf8')