1.mysql配置 1.安装pymysql pip3 install pymysql 2.在项目下__init__文件输入: import pymysql pymysql.install_as_MySQLdb() 3.在setting设置 DATABASES = { ‘default’: { ‘ENGINE’: ‘django.db.backends.mysql’, ‘NAME’: ‘django’, ‘USER’: ‘root’, ‘PASSWORD’: ‘ceshizhaohao’, ‘HOST’: ‘127.0.0.1’, ‘PORT’: ‘3306’ } }
2.项目配置 需要在新建app下的apps.py文件去找类名,比如 apps.py from django.apps import AppConfig
class DpartmentConfig(AppConfig): default_auto_field = ‘django.db.models.BigAutoField’ name = ‘Dpartment’ 在整个项目配置中加上 ‘Dpartment.apps.DpartmentConfig’ ##app名称+文件名称+类名
项目settings.py中: INSTALLED_APPS = [ ‘django.contrib.admin’, ‘django.contrib.auth’, ‘django.contrib.contenttypes’, ‘django.contrib.sessions’, ‘django.contrib.messages’, ‘django.contrib.staticfiles’, ‘Dpartment.apps.DpartmentConfig’, ]
|