1 Django和MySQL不兼容:
【现象】:在命令行中输入py manage.py runserver
后提示出如下错误
raise ImproperlyConfigured('mysqlclient 1.3.13 or newer is required; you have %s.' % Database.__version__)
django.core.exceptions.ImproperlyConfigured: mysqlclient 1.3.13 or newer is required; you have 0.9.3.
这是因为Django对于mysql是不兼容的,而且你应该已经下载了pymysql
【解决】:
- 首先确定你在__init.py__文件中有输入如下代码:
import pymysql
pymysql.install_as_MySQLdb()
- 其次找到出现问题的文件
就是错误提示中的base.py
文件,然后对这个文件进行编辑。找到如下语句,然后将这个if语句注释掉就可以了。
# 之前的代码
version = Database.version_info
if version < (1, 3, 13):
raise ImproperlyConfigured('mysqlclient 1.3.13 or newer is required; you have %s.' % Database.__version__)
# 修改之后的代码:
version = Database.version_info
# if version < (1, 3, 13):
# raise ImproperlyConfigured('mysqlclient 1.3.13 or newer is required; you have %s.' % Database.__version__)
2 URL中没东西
【现象】:
raise ImproperlyConfigured(msg.format(name=self.urlconf_name))
django.core.exceptions.ImproperlyConfigured: The included URLconf '<module '....urls' from '...'>' does not appear to have any patterns in it. If you see valid patterns in the file then the issue is probably caused by a circular import.
这是由于你的urls.py文件中没有设置任何的路由导致的,需要在其中简答设置一个路由。
3 decode问题
【现象】:
File "C:\Users\username\AppData\Local\Programs\Python\Python37\lib\site-packages\django\db\backends\mysql\operations.py", line 146, in last_executed_query
query = query.decode(errors='replace')
AttributeError: 'str' object has no attribute 'decode'
【解决】:
#原代码:
query = getattr(cursor, '_executed', None)
if query is not None:
query = query.decode(errors='replace')
return query
#修改为:
query = getattr(cursor, '_executed', None)
if query is not None:
query = query.encode(errors='replace')
return query
即,将decode修改为encode,此解决方法参考在Django框架中偶遇报错:AttributeError: ‘str’ object has no attribute ‘decode’解决办法_亭有枇杷树
4 Django的admin密码问题
在初始的admin管理界面,需要我们自己设定账号和密码,具体流程如下:
Django初始化话admin账号和密码_NTopic