Django Chinese Exception Handling

Source: Internet
Author: User

Some time ago, the following error occurred when porting A Django-Based System from English to Chinese:

Exception value:

(1366, "incorrect string value: '\ xe4 \ xb8 \ XAD \ xe5 \ x9b \ xbd' for column 'groupname' at Row 1 ")

After careful viewing, we know that Chinese characters cannot be written into the database, because the encoding method for the database connected to MySQL is "Latin1", and the encoding method of the created database is also Latin1, to solve this problem, you need to do the following:
1. change my. ini configuration file. Change default-character-set = Latin1 under [MySQL] and [mysqld] To default-character-set = utf8 (do not write it as UTF-8)
2. in addition, it is best to set the database character set to "utf8 -- UTF-8Unicode" when creating a database, so that the new table characters will be "UTF-8 ", otherwise, you must manually modify the attributes of each text class in each table.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.