问题
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