My custom 404.html, 500.html etc pages are not loading as intended. I have read lots about this and think I am doing it the correct way.
setting.py
DEBUG = False
ALLOWED_HOSTS = ['*']
# Templates Directory
TEMPLATE_DIR = os.path.join(BASE_DIR,"templates")
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [TEMPLATE_DIR],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
400.html
{% extends "tracker/index.html" %}
{% block title %}
400 - Error
{% endblock %}
{% block header %}
400 - Error
{% endblock %}
{% block content %}
{% load static %}
<h4>Error</h4>
<div class="center-image">
<img src="{% static "img/404.jpg" %}" alt="404.jpg" class="full-width">
</div>
<p class="mt-2">Have you tried turning it off and on again. </p>
{% endblock %}
Folder structure
βββ nameofproject
β βββ init.py
β βββ pycache
β βββ asgi.py
β βββ settings.py
β βββ urls.py
β βββ wsgi.py
βββ templates
β βββ 400.html
β βββ 403.html
β βββ 404.html
β βββ 500.html
β βββ desktop-index.html
β βββ mobile-index.html
β βββ registration
βββ app1
βββ app2
βββ app3
When any django app hits a problem, these custom pages donβt load. The default Django ones do instead.
For example
http://127.0.0.1:8000/hsadfjkldashf
Terminal
[22/Jan/2025 10:06:38] "GET /hsadfjkldashf HTTP/1.1" 404 179
What am I doing wrong?