Resolve Chinese errors on the configuration and management interface of the Django MySQL database

Source: Internet
Author: User
Tags python mysql django tutorial

Step 1: connect to the database

Development Environment: Ubuntu

Modify settings. py

DATABASES = {
'Default ':{
'Engine': 'django. db. backends. mysql', & nbsp;
'Name': 'blog ', & nbsp;
& Nbsp;
'User': 'root ',
'Password': 'root ',
'Host': '2017. 0.0.1 ', & nbsp;
'Port': '123', & nbsp;
}
}

Test:

>>> From django. db import connection
>>> Cursor = connection. cursor ()

No error. Connection successful!

Step 2: Management Interface Chinese submission error:

In settings. py of the Project root directory to be modified in django Configuration:

TIME_ZONE = 'America/Chicago'

Required age_code = 'en-us'

Replace:

TIME_ZONE = 'Asia/Shanghai'

Export age_code = 'zh-cn'

In the Python installation path:/usr/local/lib/python2.7/dist-packages/django/conf/global_settings.py:

TIME_ZONE = 'America/Chicago'

Required age_code = 'en-us'

Replace:

TIME_ZONE = 'Asia/Shanghai'

Export age_code = 'zh-cn'

More TIME_ZONE

Http://en.wikipedia.org/wiki/List_of_tz_zones_by_name

File encoding change (global_settings.py ):

DEFAULT_CHARSET = 'utf-8'

FILE_CHARSET = 'utf-8'

After modification, the problem cannot be solved, but the management interface is changed to Chinese, and the Chinese submission is still incorrect! The possible cause is the encoding of the database. re-create the database and add the encoding:

Create database blog character set utf8;

Chinese characters are supported.

Django details: click here
Django's: click here

Recommended reading:

Install Nginx + uWSGI + Django on Ubuntu Server 12.04

Django tutorial

Build a Django Python MySQL Linux development environment

Related Article

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.