From c6d887defe7f09bbe78ebefef6fa528ae7b225e9 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Sun, 29 Mar 2020 16:05:33 -0700 Subject: [PATCH] Adds 404 and 500 pages they only show up when debug is off though, thankfully Fixes #112 --- fedireads/templates/error.html | 10 ++++++++++ fedireads/templates/notfound.html | 9 +++++++++ fedireads/urls.py | 2 ++ fedireads/views.py | 10 ++++++++++ 4 files changed, 31 insertions(+) create mode 100644 fedireads/templates/error.html create mode 100644 fedireads/templates/notfound.html diff --git a/fedireads/templates/error.html b/fedireads/templates/error.html new file mode 100644 index 00000000..d3e51401 --- /dev/null +++ b/fedireads/templates/error.html @@ -0,0 +1,10 @@ +{% extends 'layout.html' %} +{% block content %} + +
+

Server Error

+

Something went wrong! Sorry about that.

+
+ +{% endblock %} + diff --git a/fedireads/templates/notfound.html b/fedireads/templates/notfound.html new file mode 100644 index 00000000..6c9f1b10 --- /dev/null +++ b/fedireads/templates/notfound.html @@ -0,0 +1,9 @@ +{% extends 'layout.html' %} +{% block content %} + +
+

Not Found

+

The page your requested doesn't seem to exist!

+
+ +{% endblock %} diff --git a/fedireads/urls.py b/fedireads/urls.py index c869d3c1..aa9ba362 100644 --- a/fedireads/urls.py +++ b/fedireads/urls.py @@ -13,6 +13,8 @@ local_user_path = r'^user/%s' % localname_regex status_path = r'%s/(status|review|comment)/(?P\d+)' % local_user_path book_path = r'^book/(?P[\w\-]+)' +handler404 = 'fedireads.views.not_found_page' +handler500 = 'fedireads.views.server_error_page' urlpatterns = [ path('admin/', admin.site.urls), diff --git a/fedireads/views.py b/fedireads/views.py index 0f3f2b69..0d900afd 100644 --- a/fedireads/views.py +++ b/fedireads/views.py @@ -25,6 +25,16 @@ def is_api_request(request): request.path[-5:] == '.json' +def server_error_page(request): + ''' 500 errors ''' + return TemplateResponse(request, 'error.html') + + +def not_found_page(request, _): + ''' 404s ''' + return TemplateResponse(request, 'notfound.html') + + @login_required def home(request): ''' this is the same as the feed on the home tab '''