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.