1: Django-admin. py startProject Specifies the project name

2: CD project name

3: Modify setting.py

(1) : ALLOWED_HOSTS = []=>ALLOWED_HOSTS = [" * "] (2) : LANGUAGE_CODE = 'en-us' => LANGUAGE_CODE = 'zh-Hans' (3) : TIME_ZONE = 'UTC' => TIME_ZONE = 'Asia/Shanghai'

Copy the code

4: Create app

Django - admin. Py startproject app nameCopy the code

5: Modify setting.py

INSTALLED_APPS array increment =>'app name 'Copy the code

6: Add utils folder under project directory to encapsulate multiple APP public methods

7: Util file is added in app directory to encapsulate the general method of delaying APP

8: View folder is added under app directory, which stores the logical code of each page

9: Add routing file (urls.py) in app directory to store all routes under this app

Format:  from django.urls import path from .views import wx_pay urlpatterns = [ path("test", wx_pay.wx_pay().test, Name ="test"), # test]Copy the code

10: Add APP route to project route; Modify urls.py in the project directory

from django.contrib import admin
from django.urls import path, include
from H5 import urls as h5_urls
urlpatterns = [
		path('admin/', admin.site.urls),
	path("h5/", include(h5_urls))
]
Copy the code

Now that the Django project directory structure is configured, it’s time to start development.

We often use databases in development; How to configure the database

11: Modify setting.py in the project directory

Default: DATABASES = {' default ': {' ENGINE' : 'the django. Db. Backends. Sqlite3', 'NAME' : Database = {'default': database = {'default': {' ENGINE' :'django.db.backends.mysql', 'NAME':' DATABASE1 ', 'USER':' username ', 'PASSWORD ': 'database password ', 'HOST':' IP address ', 'PORT':' PORT'}Copy the code

12: Open database add database name (DATABASE1)

13: Configure model and go to the models.py file in the app directory

import time from django.db import models # Create your models here. class Test(models.Model): STR = models.CharField(" string ", max_length=30, null=True, blank=True) num = models.IntegerField(" number ", default=1, Null =True, blank=True) create_time = models.dateTimeField (" time ", default= time.strfTime ('%Y-%m-%d %H:% m :%S'), blank=True)Copy the code

14: Migrate data to the database

python manage.py makemigrations

python manage.py migrate
Copy the code

15: There is a high probability of error as follows:

Traceback (most recent call last): Middle omitted several "/ Library/Frameworks/Python framework Versions / 3.9 / lib/python3.9 / site - packages/MySQLdb/set py", line 24, in <module> version_info, _mysql.version_info, _mysql.__file__ NameError: name '_mysql' is not definedCopy the code

This error is reported mainly because Mysqldb is not compatible with python3.5 and later

16: Change __init_. Py in the project directory and add the following code

import pymysql

pymysql.version_info = (1, 4, 13, "final", 0)

pymysql.install_as_MySQLdb()
Copy the code

Ok, so now all the usual configurations are complete