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

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

我重建了一个项目,在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

改成这样:加一个编码方式。
在这里插入图片描述
再然后再打开django后台admin,这次保存,它终于刷出了错误来了
django后台一保存就报错A server error occurred. Please contact the administrator._第1张图片

你可能感兴趣的:(python)