Django:404.html存在,但是使用了500.html [英] Django: 404.html exists but 500.html is used
问题描述
http://127.0.0.1:8000/app/slug/
使用 Debug = True
我得到找不到页面(404) - 找不到匹配查询的条目
。使用 Debug = False
我会显示 projectName / templates / 500.html
而不是 404 .html
。
With Debug=True
I get Page not found (404) - No entry found matching the query
. With Debug=False
I get shown the projectName/templates/500.html
instead of 404.html
.
两者看起来完全一样。 500.html
Both look exactly the same. 500.html
:
{% extends "base.html" %}
{% block title %}server error{% endblock %}
{% block content %}
<h3>Error 500: server error</h3>
{% endblock %}
404。 html
:
{% extends "base.html" %}
{% block title %}page not found{% endblock %}
{% block content %}
<h3>Error 404: page not found</h3>
{% endblock %}
为什么Django加载500而不是404虽然存在?它不能是模板错误。
Why does Django load 500 instead of 404 although it exists? It cannot be a template error.
推荐答案
如果您确信您已经在设置中正确设置了ALLOWED_HOSTS有可能你的404.html模板是不正确的。可能会出现语法错误(或者找不到基本模板),这反而会引起新的500异常。
If you're 100% sure that you've correctly set up ALLOWED_HOSTS in your settings, chances are your 404.html template is somehow not correct. There might be a syntax error (or it can't find the base template), which, in turn, causes a new 500 exception to be raised.
尝试简化您的404.html只包含静态HTML。
Try simplifying your 404.html by only including static HTML.
这篇关于Django:404.html存在,但是使用了500.html的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!