How to use MySql in combination with Python3.4 in Django1.6

Source: Internet
Author: User
How to use MySql pythonDjango in combination with Python3.4 in Django1.6

Alas, a new wave recently emerged, using Python3.4 and Django1.6. databases are still common MySql for Internet enterprises.

Sadly, MySQLdb connected to MySql in the Python2.7 era does not support Python3.4 yet. Fortunately, I am struggling to ask G brother to find a replacement product and the effect is good. this replacement product is pymysql.

Download this item and install it. it is the same as other python third package.

The DATABASES settings in Django1.6 are the same as those in MySQLdb, as shown below:

1 DATABASES = {2 'default': {3 'engine': 'Django. db. backends. mysql ', # Database Engine 4 'name': 'test', # Database NAME 5 'user': 'root', # Username 6 'password': 'root ', # Password: 7'host': '', # Database HOST. the default value is localhost 8 'port':'', # Database PORT. MySQL defaults to 3306 'options ': {10 'autocommit ': True, 11}, 12} 13}

The most critical point is to add the following code in the _ init _. py file of the site:

1 import pymysql2 pymysql. install_as_MySQLdb ()

After completing the preceding steps, you can access mysql in django.

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.