Environment: Centos6.6, python2.6
Preparatory work:
MySQL installation, as well as the installation of Mysql-python http://www.cnblogs.com/zychengzhiit1/p/4437310.html
1. Create a Python project
django-admin.py Startproject Pythondemo
2. Enter the created project directory Pythondemo to create the Python app
django-admin.py Startapp Blog
3. Configure settings.py
Changes in several places:
Modify:
ENGINE:django.db.backend.mysql (using MySQL database)
Name:demo (to create a good db in MySQL now)
User:root (MySQL login name)
Password:root (MySQL login password)
Host: (Master IP)
Port: (port number)
Add the name of the Python app;
4.code-first, importing a model from a class
Vim models.py # Modified models.py from Import Models class Employee (models. Model): = models. Charfield (MAX_LENGHT=20)
5. According to the structure of the custom class, synchronize the MySQL table and the structure of the table (Blog_employee table, Name field and primary key ID)
Python manage.py syncdb
After synchronization, look at the MySQL table and the table structure:
Table name: Python app name + custom class name
Table structure: Fields for custom classes
At this point, your Django framework's Python application, the data model corresponds to the MySQL table structure;
Python's Django uses MySQL basic operations