当前位置: 代码迷 >> 综合 >> django后台一保存就报错A server error occurred. Please contact the administrator.
  详细解决方案

django后台一保存就报错A server error occurred. Please contact the administrator.

热度:31   发布时间:2023-12-22 02:38:47.0

后台数据一保存就报错,而且不告诉你为什么错。

我重建了一个项目,在cmd里运行,终于发现了错误的痕迹。

Traceback (most recent call last):File "D:\python\lib\site-packages\django\core\handlers\exception.py", line 34, in innerresponse = 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 innerresponse = response_for_exception(request, exc)File "D:\python\lib\site-packages\django\core\handlers\exception.py", line 90, in response_for_exceptionresponse = 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_exceptionreturn debug.technical_500_response(request, *exc_info)File "D:\python\lib\site-packages\django\views\debug.py", line 94, in technical_500_responsehtml = reporter.get_traceback_html()File "D:\python\lib\site-packages\django\views\debug.py", line 332, in get_traceback_htmlt = 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

改成这样:加一个编码方式。
在这里插入图片描述
再然后再打开django后台admin,这次保存,它终于刷出了错误来了
在这里插入图片描述

  相关解决方案