Update urls & add custom error pages
This commit is contained in:
parent
ce5031b64f
commit
0787465224
5 changed files with 58 additions and 10 deletions
|
@ -2,12 +2,16 @@ from django.conf import settings
|
||||||
from django.conf.urls.static import static
|
from django.conf.urls.static import static
|
||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
from django.urls import include, path
|
from django.urls import include, path
|
||||||
|
from django.views.generic import RedirectView
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path('admin/', admin.site.urls),
|
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:
|
if settings.DEBUG:
|
||||||
urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
|
urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
|
||||||
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
|
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
from django.shortcuts import redirect
|
|
||||||
from django.urls import path
|
from django.urls import path
|
||||||
|
|
||||||
from . import views
|
from . import views
|
||||||
|
@ -15,8 +14,3 @@ urlpatterns = [
|
||||||
path('albums/', views.AlbumsList.as_view(), name='albums_url'),
|
path('albums/', views.AlbumsList.as_view(), name='albums_url'),
|
||||||
path('<path:redir_path>/', views.redirect_to_album, name='redirect_to_album'),
|
path('<path:redir_path>/', views.redirect_to_album, name='redirect_to_album'),
|
||||||
]
|
]
|
||||||
|
|
||||||
def custom_404_view(request, exception):
|
|
||||||
return redirect('/')
|
|
||||||
|
|
||||||
handler404 = 'gallery.urls.custom_404_view'
|
|
|
@ -1,5 +1,3 @@
|
||||||
from collections import defaultdict
|
|
||||||
|
|
||||||
from django.core.paginator import Paginator
|
from django.core.paginator import Paginator
|
||||||
from django.shortcuts import get_object_or_404, redirect
|
from django.shortcuts import get_object_or_404, redirect
|
||||||
from django.views.generic import DetailView, ListView, TemplateView
|
from django.views.generic import DetailView, ListView, TemplateView
|
||||||
|
@ -93,7 +91,7 @@ class About(TemplateView):
|
||||||
template_name = "gallery/about.html"
|
template_name = "gallery/about.html"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def redirect_to_album(request, redir_path):
|
def redirect_to_album(request, redir_path):
|
||||||
redir = get_object_or_404(Redir, path=redir_path)
|
redir = get_object_or_404(Redir, path=redir_path)
|
||||||
return redirect('gallery:album_url', album_slug=redir.album.slug)
|
return redirect('gallery:album_url', album_slug=redir.album.slug)
|
||||||
|
|
||||||
|
|
26
templates/404.html
Normal file
26
templates/404.html
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>404 - Page not found</title>
|
||||||
|
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/uikit@3.16.24/dist/css/uikit.min.css" />
|
||||||
|
<script src="https://cdn.jsdelivr.net/npm/uikit@3.16.24/dist/js/uikit.min.js"></script>
|
||||||
|
<script src="https://cdn.jsdelivr.net/npm/uikit@3.16.24/dist/js/uikit-icons.min.js"></script>
|
||||||
|
<meta http-equiv="refresh" content="3;url=/" />
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
|
||||||
|
<div class="uk-section uk-section-large uk-flex uk-flex-middle uk-text-center" style="height: 100vh;">
|
||||||
|
<div class="uk-container">
|
||||||
|
<span uk-icon="icon: warning; ratio: 4" class="uk-text-danger"></span>
|
||||||
|
<h1 class="uk-heading-medium uk-text-bold uk-margin-small-top">404</h1>
|
||||||
|
<p class="uk-text-large uk-text-muted">Oops! The page you were looking for was not found.</p>
|
||||||
|
<a href="/" class="uk-button uk-button-primary uk-margin-top">
|
||||||
|
<span uk-icon="home"></span> Return to homepage
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
26
templates/500.html
Normal file
26
templates/500.html
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>500 - Server Error</title>
|
||||||
|
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/uikit@3.16.24/dist/css/uikit.min.css" />
|
||||||
|
<script src="https://cdn.jsdelivr.net/npm/uikit@3.16.24/dist/js/uikit.min.js"></script>
|
||||||
|
<script src="https://cdn.jsdelivr.net/npm/uikit@3.16.24/dist/js/uikit-icons.min.js"></script>
|
||||||
|
<meta http-equiv="refresh" content="3;url=/" />
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
|
||||||
|
<div class="uk-section uk-section-large uk-flex uk-flex-middle uk-text-center" style="height: 100vh;">
|
||||||
|
<div class="uk-container">
|
||||||
|
<span uk-icon="icon: bolt; ratio: 4" class="uk-text-danger"></span>
|
||||||
|
<h1 class="uk-heading-medium uk-text-bold uk-margin-small-top">500</h1>
|
||||||
|
<p class="uk-text-large uk-text-muted">Oops! Something went wrong with the server.</p>
|
||||||
|
<a href="/" class="uk-button uk-button-primary uk-margin-top">
|
||||||
|
<span uk-icon="home"></span> Return to homepage
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
Loading…
Add table
Reference in a new issue