Chinese garbled characters in Djangoz _ MySQL

Source: Internet
Author: User
Djangoz Chinese garbled problem Django

Recently, I was learning about the Django website architecture.

Related languages and software versions involved:

Operating system: win8

Python: 2.7.5

Django: 1.5.5

Mysql: 5.5.24


Files to be changed:

1. in the settings. py file of the current project

TIME_ZONE = 'America/Chicago'LANGUAGE_CODE = 'en-us'

Change

TIME_ZONE = 'Asia/Shanghai'LANGUAGE_CODE = 'zh-cn'

2. in the python installation directory, there is a global_settings.py file in/Lib/site-packages/django/conf.
TIME_ZONE = 'America/Chicago'LANGUAGE_CODE = 'en-us'DEFAULT_CHARSET = 'utf-8'# Encoding of files read from disk (template and initial SQL files).FILE_CHARSET = 'utf-8'

Change:

TIME_ZONE = 'Asia/Shanghai'LANGUAGE_CODE = 'zh-cn'DEFAULT_CHARSET = 'utf-8'# Encoding of files read from disk (template and initial SQL files).FILE_CHARSET = 'gb18030'

3. after the modification, the Chinese HTML file can be displayed. However, when calling the database, you must modify the character type of the database (take MySQL as an example ), there is a solution on the Internet that you can install MySQL under my. in the ini file, "default-character-set =" is GB2312 or UTF-8, but I did not find the file, so I use the following command when creating the database:

CREATE DATABASE dbname DEFAULT CHARACTER SET utf8

In this way, Chinese characters are fully supported.

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.