1. Modifying settings.py Configuration Data Properties
DATABASES = {'default': {'ENGINE':'Django.db.backends.mysql','NAME':'Fruitdb','USER':'Root','PASSWORD':'Hellosandy',}}
After the modification, enter the terminal into the project directory to execute the Python manage.py shell command to start the interactive interface enter the code to verify that the database configuration is successful. No error is successful!
from Import connection>>> cursor = connection.cursor ()
2. Create a Django app
The terminal enters the project directory to execute the Python manage.py startapp Register generated directory file as follows:
products/ __init__. py models.py tests.py views.py
3. Writing Models
from django.db import models # Create your models here. class Register (models. Model): Nickname = models. Charfield (Max_length=30 = models. Charfield (Max_length=50 = models. Charfield (Max_length=30) def __unicode__ return Span style= "color: #800000;" > " %s,%s,%s " % (Self.nickname, Self.email, Self.password)
4. model Installation (modify settings.py)
Installed_apps = ( 'Django.contrib.admin', 'Django.contrib.auth', 'Django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'Django.contrib.staticfiles', 'Register',)
Use Python manage.py validate to check that the model's syntax and logic are correct.
Without errors, execute the Python manage.py syncdb to create the data table.
sandymatomacbook-pro:fruitproject sandy$ python manage.py validate0errors Foundsandymatomacbook-Pro: Fruitproject sandy$ python manage.py syncdbcreating tables ... Creating table django_admin_logcreating table auth_permissioncreating table auth_group_permissionscreating table Auth_ groupcreating table auth_user_groupscreating table auth_user_user_permissionscreating table auth_usercreating table django_content_typecreating table django_sessioncreating Table Register_register
Now you can see that your database has created several other tables in addition to Register_register, which are the tables that the Django management background requires.
Django connects to MySQL database