- Create a project
>django-admin startproject project01
- Creating an application
>python manage.py startapp app01
- settings.py configuration INSTALLED_APPS
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'app01', #添加创建的app名称
]
- settings.py configuration STATICFILES_DIRS
STATIC_URL = '/static/'
STATICFILES_DIRS = ( #添加静态文件目录,并在项目下创建static文件夹
os.path.join(BASE_DIR, 'static'),
)
- settings.py configuration to connect MySQL database
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'Djangoorm', #数据库名称
'USER': 'dongfei', #数据库用户名
'PASSWORD': 'dongfei', #数据库密码
'HOST': '192.168.56.101', #数据库主机,留空默认为localhost
'PORT': '3306', #数据库端口
}
}
- Initialize the database table
>python manage.py makemigrations
>python manage.py migrate