1.确保已经安装好python和Django
2.创建django项目
3.打开setting.py配置文件
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'blog', //数据库名称
'USER': 'root', //用户名
'PASSWORD': '123456', //密码
'HOST': 'localhost', //地址
'PORT': '3306', //端口
}
}
4.查看是否安装有pymysql,若未安装,使用pip install pymysql
5.进入django项目根目录,运行程序:
python manage.py runserver
程序会显示如下错误:
_mysql.c(29): fatal error C1083: 无法打开包括文件: “mysql.h”: No such file or directory
error: command 'D:\\vs2015\\VC\\BIN\\amd64\\cl.exe' failed with exit status 2
这是驱动的问题,往下面的链接中下载MySQL-python-1.2.3.win-amd64-py2.7.exe<