From 0787465224286f58eead0424b4cb06a64f2b2d2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9DNyymix=E2=80=9D?= Date: Sat, 22 Mar 2025 00:46:17 +0200 Subject: [PATCH] Update urls & add custom error pages --- config/urls.py | 6 +++++- gallery/urls.py | 6 ------ gallery/views.py | 4 +--- templates/404.html | 26 ++++++++++++++++++++++++++ templates/500.html | 26 ++++++++++++++++++++++++++ 5 files changed, 58 insertions(+), 10 deletions(-) create mode 100644 templates/404.html create mode 100644 templates/500.html diff --git a/config/urls.py b/config/urls.py index daa6e4d..4cfe859 100644 --- a/config/urls.py +++ b/config/urls.py @@ -2,12 +2,16 @@ from django.conf import settings from django.conf.urls.static import static from django.contrib import admin from django.urls import include, path +from django.views.generic import RedirectView urlpatterns = [ path('admin/', admin.site.urls), - path('', include(('gallery.urls', 'gallery'), namespace='gallery')), + path('favicon.ico/', RedirectView.as_view(url='/static/favicon.ico', permanent=True)), + path('', include(('gallery.urls', 'gallery'), namespace='gallery')), ] if settings.DEBUG: urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT) urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) + + diff --git a/gallery/urls.py b/gallery/urls.py index 27c69ff..65c5c6c 100644 --- a/gallery/urls.py +++ b/gallery/urls.py @@ -1,4 +1,3 @@ -from django.shortcuts import redirect from django.urls import path from . import views @@ -15,8 +14,3 @@ urlpatterns = [ path('albums/', views.AlbumsList.as_view(), name='albums_url'), path('/', views.redirect_to_album, name='redirect_to_album'), ] - -def custom_404_view(request, exception): - return redirect('/') - -handler404 = 'gallery.urls.custom_404_view' \ No newline at end of file diff --git a/gallery/views.py b/gallery/views.py index 89af30b..b8b627e 100644 --- a/gallery/views.py +++ b/gallery/views.py @@ -1,5 +1,3 @@ -from collections import defaultdict - from django.core.paginator import Paginator from django.shortcuts import get_object_or_404, redirect from django.views.generic import DetailView, ListView, TemplateView @@ -93,7 +91,7 @@ class About(TemplateView): template_name = "gallery/about.html" - def redirect_to_album(request, redir_path): redir = get_object_or_404(Redir, path=redir_path) return redirect('gallery:album_url', album_slug=redir.album.slug) + diff --git a/templates/404.html b/templates/404.html new file mode 100644 index 0000000..79360d4 --- /dev/null +++ b/templates/404.html @@ -0,0 +1,26 @@ + + + + + + 404 - Page not found + + + + + + + +
+
+ +

404

+

Oops! The page you were looking for was not found.

+ + Return to homepage + +
+
+ + + \ No newline at end of file diff --git a/templates/500.html b/templates/500.html new file mode 100644 index 0000000..bd21fb0 --- /dev/null +++ b/templates/500.html @@ -0,0 +1,26 @@ + + + + + + 500 - Server Error + + + + + + + +
+
+ +

500

+

Oops! Something went wrong with the server.

+ + Return to homepage + +
+
+ + + \ No newline at end of file