Django Uses:
1. Install the django:< database using MySQL version >
1.Django 1.9.52.MySQL 5.5 345.python2.7.11 (or above)
1.1 Installing the module Process <windows 7 environment >
1. Unzip the downloaded Django package to the path of your choice (e.g. c:/Django195) 2. Go to DOS command line, CD c:/django195 3. Python setup.py Install (Setup Django) 4. Install MYSQLDB module in the same way 5. Edit the value of the environment variable path (if import in idle Django or import mysqldb appear importerror words) at the end add "; C:\Python27\Scripts; C:\Python27\Lib\site-packages" 6. Install Mysql5.5,sqlyog
1.2 Configuration
1.2.1 Configuring MySQL
(1). setting
Host: "127.0.0.1" User:"root" passwd:"xxxxx" port:3306
(2). Create a database:
Go to MySQL under MySQL Commandline:
Create DATABASE MyDatabase set CharSet UTF8
(3). Test the database connection to Python:
In the Python interpreter:
>>>Import mysqldb >>>db = MySQLdb.connect (user='root ', passwd='xxxxx', db='mydatabase', host= ' 127.0.0.1 ', port=3306) >>>
Success without error
1.2.2 Configuring Django
1. Go to dos and switch to the path where you want to create the Django project (for example: c:/) 2. Input: Django-admin startproject MyProject $ At this point C:/ path There will be a folder named MyProject, whose directory structure is as follows: myproject manage.py myproject __init_ _. py settings.py urls.py wsgi.py 3. If the database uses Sqlite3, The first time you use Django, you need to migrate the database to ensure that the database exists so that you can create superuser for site Administration in the directory where manage.py is entered: python manage.py Migrate can create superuser after successful, enter: python manage.py createsuperuser
1.3 Use
1.3.1 Modifying the settings of Django Project:
1. Make the Background Management page display in Chinese:#Modify Time zone Time_zone: ' Asia/shanghai ' #Modify the display language language_code: ' ZH-CN '2. Create an app3. Add template path: TEMPLATES:'DIRS': [Os.path.join (Os.path.dirname (__file__),'Templates'),], 4. Add Installed_app5. Configuring Mysql:databases= { 'default': { 'ENGINE':'Django.db.backends.mysql', 'HOST':'127.0.0.1', 'USER':'Root', 'PASSWORD':'xxxxx', 'PORT': 3306, 'NAME':'MyDatabase', } } 6 .....
1.3.2 New views.py View function library
1.3.3 The URL that is bound to the access in urls.py and the associated View function in views.py
1.4 Creating an App
1.4.1 under the project catalog MyProject:
django-admin Startapp myapp 1. Django automatically generates a folder in MyApp under myproject 2. Set the Installed_apps in the myproject settings.py file:= [ 'myapp' , ]
Django1.9.5 Log (0x00)