后台数据一保存就报错,而且不告诉你为什么错。
我重建了一个项目,在cmd里运行,终于发现了错误的痕迹。
Traceback (most recent call last):
File "D:\python\lib\site-packages\django\core\handlers\exception.py", line 34, in inner
response = get_response(request)
File "D:\python\lib\site-packages\django\utils\deprecation.py", line 94, in __call__
response = response or self.get_response(request)
File "D:\python\lib\site-packages\django\core\handlers\exception.py", line 36, in inner
response = response_for_exception(request, exc)
File "D:\python\lib\site-packages\django\core\handlers\exception.py", line 90, in response_for_exception
response = handle_uncaught_exception(request, get_resolver(get_urlconf()), sys.exc_info())
File "D:\python\lib\site-packages\django\core\handlers\exception.py", line 125, in handle_uncaught_exception
return debug.technical_500_response(request, *exc_info)
File "D:\python\lib\site-packages\django\views\debug.py", line 94, in technical_500_response
html = reporter.get_traceback_html()
File "D:\python\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
又是编码问题。。
分析代码:主要是找到下面这个文档,然后找到332行的代码。
File “D:\python\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