0
点赞
收藏
分享

微信扫一扫

django1.11 和 django2.2 启动错误

1kesou 2022-03-12 阅读 79
djangopython

django1.11.11 启动错误

报错:

SyntaxError: Generator expression must be parenthesized (widgets.py, line 152)

由于django 1.11.17之前的版本和python3.7版本不兼容, 2.0版本以后的Django修复了这个问题
django与python版本兼容对照:https://blog.csdn.net/qq_28770757/article/details/123415364

解决方法1.找到对应路径下的widgets.py,将逗号删除即可
在这里插入图片描述
解决方法2.升级Django版本
升级的稳定的2.2LTS版本
django稳定版本更新时间:https://blog.csdn.net/qq_28770757/article/details/123415364

pip3 install Django==2.2 

django2.2启动报错

  File "D:\python\django\venv\lib\site-packages\django\views\debug.py", line 332, in get_traceback_html
    t = DEBUG_ENGINE.from_string(fh.read())

UnicodeDecodeError: 'gbk' codec can't decode byte 0xa6 in position 9737: illegal multibyte sequence

报错显示该版本django的debug.py代码文件有编码读取问题。
解决:
根据提示定位到 python安装路径\lib\site-packages\django\views\debug.py文件的332 行处,将:

with Path(CURRENT_DIR, 'templates', 'technical_500.html').open() as fh:

修改为

with Path(CURRENT_DIR, 'templates', 'technical_500.html').open(encoding='utf-8') as fh:

在这里插入图片描述
也就是进行编码设置 ,重新启动页面即可正常显示。

举报

相关推荐

0 条评论