add error pages
This commit is contained in:
parent
43f00dbaa7
commit
6cfbc516f8
6 changed files with 87 additions and 0 deletions
BIN
hub/services/static/img/sir-vala-notext.png
Normal file
BIN
hub/services/static/img/sir-vala-notext.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 92 KiB |
20
hub/services/templates/400.html
Normal file
20
hub/services/templates/400.html
Normal file
|
@ -0,0 +1,20 @@
|
|||
{% extends 'services/base.html' %}
|
||||
{% load static %}
|
||||
|
||||
{% block title %}Bad Request (400){% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<section class="section">
|
||||
<div class="container mx-auto px-20 px-lg-0 pt-80 pb-60">
|
||||
<div class="page-card">
|
||||
<div class="text-center">
|
||||
<h1 class="fs-50 fw-semibold lh-1 mb-24">400</h1>
|
||||
<h2 class="fs-24 fw-semibold mb-16">Bad Request</h2>
|
||||
<p class="fs-19 text-gray-500 mb-24">Sorry, your request contains invalid syntax and cannot be fulfilled.</p>
|
||||
<img src="{% static "img/sir-vala-notext.png" %}" alt="sir vala mascot" class="img-fluid mb-4">
|
||||
<p><a href="{% url 'services:homepage' %}" class="btn btn-primary btn-lg">Return to Homepage</a></p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
{% endblock %}
|
20
hub/services/templates/404.html
Normal file
20
hub/services/templates/404.html
Normal file
|
@ -0,0 +1,20 @@
|
|||
{% extends 'services/base.html' %}
|
||||
{% load static %}
|
||||
|
||||
{% block title %}Page Not Found (404){% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<section class="section">
|
||||
<div class="container mx-auto px-20 px-lg-0 pt-80 pb-60">
|
||||
<div class="page-card">
|
||||
<div class="text-center">
|
||||
<h1 class="fs-50 fw-semibold lh-1 mb-24">404</h1>
|
||||
<h2 class="fs-24 fw-semibold mb-16">Page Not Found</h2>
|
||||
<p class="fs-19 text-gray-500 mb-24">Sorry, the page you are looking for does not exist or has been moved.</p>
|
||||
<img src="{% static "img/sir-vala-notext.png" %}" alt="sir vala mascot" class="img-fluid mb-4">
|
||||
<p><a href="{% url 'services:homepage' %}" class="btn btn-primary btn-lg">Return to Homepage</a></p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
{% endblock %}
|
20
hub/services/templates/500.html
Normal file
20
hub/services/templates/500.html
Normal file
|
@ -0,0 +1,20 @@
|
|||
{% extends 'services/base.html' %}
|
||||
{% load static %}
|
||||
|
||||
{% block title %}Server Error (500){% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<section class="section">
|
||||
<div class="container mx-auto px-20 px-lg-0 pt-80 pb-60">
|
||||
<div class="page-card">
|
||||
<div class="text-center">
|
||||
<h1 class="fs-50 fw-semibold lh-1 mb-24">500</h1>
|
||||
<h2 class="fs-24 fw-semibold mb-16">Server Error</h2>
|
||||
<p class="fs-19 text-gray-500 mb-24">Sorry, something went wrong on our server. Our team has been notified.</p>
|
||||
<img src="{% static "img/sir-vala-notext.png" %}" alt="sir vala mascot" class="img-fluid mb-4">
|
||||
<p><a href="{% url 'services:homepage' %}" class="btn btn-primary btn-lg">Return to Homepage</a></p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
{% endblock %}
|
16
hub/services/views/errors.py
Normal file
16
hub/services/views/errors.py
Normal file
|
@ -0,0 +1,16 @@
|
|||
from django.shortcuts import render
|
||||
|
||||
|
||||
def bad_request(request, exception):
|
||||
"""400 error handler"""
|
||||
return render(request, "400.html", status=400)
|
||||
|
||||
|
||||
def page_not_found(request, exception):
|
||||
"""404 error handler"""
|
||||
return render(request, "404.html", status=404)
|
||||
|
||||
|
||||
def server_error(request):
|
||||
"""500 error handler"""
|
||||
return render(request, "500.html", status=500)
|
11
hub/urls.py
11
hub/urls.py
|
@ -1,8 +1,16 @@
|
|||
from django.conf import settings
|
||||
from django.conf.urls import handler400, handler404, handler500
|
||||
from django.conf.urls.static import static
|
||||
from django.contrib import admin
|
||||
from django.shortcuts import render
|
||||
from django.urls import path, include
|
||||
|
||||
from hub.services.views.errors import bad_request, page_not_found, server_error
|
||||
|
||||
handler400 = "hub.services.views.errors.bad_request"
|
||||
handler404 = "hub.services.views.errors.page_not_found"
|
||||
handler500 = "hub.services.views.errors.server_error"
|
||||
|
||||
urlpatterns = [
|
||||
path("admin/", admin.site.urls),
|
||||
path("", include("hub.services.urls")),
|
||||
|
@ -12,5 +20,8 @@ if settings.DEBUG:
|
|||
urlpatterns += [
|
||||
path("__reload__/", include("django_browser_reload.urls")),
|
||||
path("schema-viewer/", include("schema_viewer.urls")),
|
||||
path("test-400/", lambda request: render(request, "400.html"), name="test_400"),
|
||||
path("test-404/", lambda request: render(request, "404.html"), name="test_404"),
|
||||
path("test-500/", lambda request: render(request, "500.html"), name="test_500"),
|
||||
]
|
||||
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue