Django: 404.html exists but 500.html is used

蹲街弑〆低调 提交于 2019-12-13 06:25:39

问题


http://127.0.0.1:8000/app/slug/

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.

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 %}

Why does Django load 500 instead of 404 although it exists? It cannot be a template error.


回答1:


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.

Try simplifying your 404.html by only including static HTML.



来源:https://stackoverflow.com/questions/17921753/django-404-html-exists-but-500-html-is-used

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!