NameError: name '_mysql' is not defined

安装PyMySQL:注意:命令中的PyMySQL是区分大小写的,不能写错。

pip install PyMySQL

Collecting PyMySQL
Downloading PyMySQL-1.0.2-py3-none-any.whl (43 kB)
|████████████████████████████████| 43 kB 457 kB/s
Installing collected packages: PyMySQL
Successfully installed PyMySQL-1.0.2

在seetings.py所在目录的__init__.py文件中添加:

import pymysql
pymysql.install_as_MySQLdb()

然后重新启动即可:

python manage.py runserver 0.0.0.0:8000

文章出处:www.cnblogs.com/jizhong

本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接。否则保留追究法律责任的权利。

原文地址:https://www.cnblogs.com/jizhong/p/15161490.html