Django2.2 安装后,使用runserver进行开发,出错时错误信息只显示于控制台命令行,而在前端页面只显示一行
“A server error occurred. Please contact the administrator.”
排错很不方便,仔细查看控制台的错误信息,提示
nicodeDecodeError: 'gbk' codec can't decode byte 0xa6 in position 9737: illegal multibyte sequence
判断这个版本django由于出错信息的代码有编码读取问题 造成无法正常显示。
根据提示找到 python安装路径\Lib\site-packages\django\views\debug.py
,打开后,修改约在 331 行处,将:
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:
这样就便于排错了。