升级依赖包
推荐直接使用pip install Django==2.2.11
直接进行安装。
从压缩包解压安装生成的目录与pip安装生成的有所不同。
出现问题,按安装提示信息解决即可。
坑爹问题-1
-
问题:
list index out of range
-
解决:
我的项目Django2.1的代码里有这两行,删除即可
from httprunner import logger
logger.setup_logger('INFO')
- 备注
这里的调试简直就无敌恶心了,控制台报错就只有这简短的一条信息,堆栈也没有,我整整调试了一天,才定位到上面的问题,也不知道为什么Django2.2不支持。
我的调试方法是:逐步定位出问题的模块。
1.对项目根目录的urls.py
的配置进行逐个注释,然后重启服务,定位到出问题的app;
2.然后对app里的urls
逐个注释以及导入,从而定问到出问题的view
;
3.最后在有问题的view
里逐行注释import
语句,最终定位到logger.setup_logger('INFO')
坑爹问题-2
- 问题:
Django2.2删除了allow_thread_sharing
,如果使用gevent会有报错django.db.utils.DatabaseError: DatabaseWrapper objects created in a thread can only be used in that same thread. The object with alias 'default' was created in thread id 140418043918144 and this is thread id 140418015765920.
- 解决:
Django2.2 在manage.py
中加入如下代码
import platform
from gevent import monkey
if platform.system() == "Windows":
monkey.patch_ssl()
else:
# Linux, Darwin
monkey.patch_all()
- 备注:
在Django2.1中,manage.py
代码如下:
from gevent import monkey
monkey.patch_ssl()
from django.db import connection
# Allow thread sharing to ensure that Django database connection
# works properly with gevent.
connection.allow_thread_sharing = True
坑爹问题-3
- 问题:
django.template.exceptions.TemplateDoesNotExist: django/forms/widgets/text.html
- 解决:
需要在settings.py
中,增加
INSTALLED_APPS = [
"django.forms"
]
出现其他的问题,再更新此文档。
网友评论