Django2.2 报错信息无法正常在页面显示

Django2.2 报错信息无法正常在页面显示

Django2.2 安装后,使用runserver进行开发,出错时错误信息只显示于控制台命令行,而在前端页面只显示一行

A server error occurred. Please contact the administrator.

排错很不方便,仔细查看控制台的错误信息,提示

UnicodeDecodeError: ‘gbk‘ codec can‘t decode byte 0xa6 in position 9737: ill....

判断这个版本django由于出错信息的代码有编码读取问题 造成无法正常显示。
根据提示找到 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:

也就是进行编码设置 ,然后再重新 启动runserver,出错信息即可正常显示在页面显示。

转载于:https://blog.51cto.com/firelife/2377067

原文地址:https://www.cnblogs.com/yywq/p/12362566.html

时间: 2024-08-04 12:17:46

Django2.2 报错信息无法正常在页面显示的相关文章

JavaWeb: 报错信息The superclass "javax.servlet.http.HttpServlet" was not found on the Java Build Path

JavaWeb: 报错信息The superclass "javax.servlet.http.HttpServlet" was not found on the Java Build Path 好久不写Jsp,今天建立了一个Javaweb工程,并在eclipse中配置了Web容器Tomcat.原本开心的新建jsp页面,添加一个简单的Java类.可是,JSP页面顶端出现“红色”的报错信息:The superclass "javax.servlet.http.HttpServl

eclipse:报错信息The superclass "javax.servlet.http.HttpServlet" was not found on the Java Build Path

JavaWeb: 报错信息The superclass "javax.servlet.http.HttpServlet" was not found on the Java Build Path 今天建立了一个Javaweb工程,并在eclipse中配置了Web容器Tomcat.JSP页面顶端出现“红色”的报错信息:The superclass "javax.servlet.http.HttpServlet" was not found on the Java Bu

Maven项目红色叹号+JavaWeb: 报错信息The superclass "javax.servlet.http.HttpServlet" was not found on the Java B

昨天写的关于解决JavaWeb: 报错信息The superclass "javax.servlet.http.HttpServlet" was not found on the Java的方案非常好的攻克了这个错误,可是它没有全然的解决我的问题,Maven项目依旧有一个红色叹号存在.红色叹号存在的原因是:.classpath配置文件引用了某jar包,可是lib里却不存在此jar.我所遇到的问题又是一种新的情况,jar存在lib里存在,但还是报题目中的两个错误.细致研究发现我的java

【SSH权限故障】   报错信息:Connection closed by

SSH权限故障 故障现象:业务反馈一台虚拟机无法登陆,早晨还好好的 报错信息: [[email protected] ~]# ssh 10.12.141.111 Connection closed by 10.12.141.111 没有台明显的报错,然后-v [[email protected] ~]# ssh -v 10.12.141.111 OpenSSH_5.3p1, OpenSSL 1.0.1e-fips 11 Feb 2013 debug1: Reading configuration

【php】开启与关闭调试与报错信息

开启调试与报错信息有利于编程人员掌握出错的位置,从而更快地解决问题. 关闭调试信息,则在你的网页发布时候,用户看不到你的php出现运行错误,当然也不会看到正确东西,仅仅会是一篇空白. 关键是在php安装之后,忘记开启调试与报错信息,在你编程的时候写错代码,却发现php没有报错,会产生一头雾水,此时你要关注你的php安装目录下的php.ini 如下图,找到display_errors那行,注意把Off,改成On,On的第一个字母注意大写.反之亦然. 同时,重启一下你的 Apache服务器. 此时你

tomcat部署新的项目的时候出现报错信息: Invalid byte tag in constant pool: 15

上面一堆tomcat启动的提示信息省略掉,下面是报错的具体信息:org.apache.tomcat.util.bcel.classfile.ClassFormatException: Invalid byte tag in constant pool: 15 at org.apache.tomcat.util.bcel.classfile.Constant.readConstant(Constant.java:131) at org.apache.tomcat.util.bcel.classfi

动态添加Fragment的报错信息

05-29 21:23:28.406: E/AndroidRuntime(23636): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.***.Main}: java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent

JavaWeb:报错信息The superclass "javax.servlet.http.HttpServlet" was not found on the Java Build Path 解决办法

JavaWeb: 报错信息The superclass "javax.servlet.http.HttpServlet" was not found on the Java Build Path 好久不写Jsp,今天建立了一个Javaweb工程,并在eclipse中配置了Web容器Tomcat.原本开心的新建jsp页面,添加一个简单的Java类.可是,JSP页面顶端出现"红色"的报错信息:The superclass "javax.servlet.http

SVN Cornerstone 报错信息 xcodeproj cannot be opened because the project file cannot be parsed.

svn点击update 之后,打开xcode工程文件,会出现  xxx..xcodeproj  cannot be opened becausethe project file cannot be parsed. 发现项目中代码全没了.只有一个空的工程名字,因为xcodeproj工程文件冲突了,然后就是svn强制给你更新了,内部的文件冲突了,你们改了同样的地方的一段代码,可能是你们只是多加了一个空格,或者你们都加了代码,或者都是把对方的删了,自己又加的.所有svn不知道你们谁的对,到底听你们谁的