errors should work but dont

This commit is contained in:
Christoph J. Scherr 2023-06-06 21:32:41 +02:00
parent 1570c34075
commit 011c967446
Signed by: PlexSheep
GPG Key ID: 25B4ACF7D88186CC
4 changed files with 39 additions and 12 deletions

View File

@ -33,6 +33,7 @@ urlpatterns += i18n_patterns(
# use my fancy error pages # use my fancy error pages
# better yet, don't let it come to that # better yet, don't let it come to that
# FIXME these break the server. something is wrong with them # FIXME these break the server. something is wrong with them
#handler400 = 'start.views.Error400' handler400 = 'start.views.Error400'
#handler404 = 'start.views.Error404' handler403 = 'start.views.Error403'
handler404 = 'start.views.Error404'
#handler500 = 'start.views.Error500' #handler500 = 'start.views.Error500'

View File

@ -5,7 +5,7 @@
{% block title %}{% translate "cscherr.de" %} - {% translate "startpage" %}{% endblock title %} {% block title %}{% translate "cscherr.de" %} - {% translate "startpage" %}{% endblock title %}
{% block main %} {% block main %}
<div class="jumbotron text-center"> <div class="jumbotron text-center">
<h1>404 {% translate "Bad request" %}</h1> <h1>400 {% translate "Bad request" %}</h1>
<p>{% translate "You sent bad data to the server." %}</p> <p>{% translate "You sent bad data to the server." %}</p>
</div> </div>
<div class="container text-center jumbotron my-5" py-5> <div class="container text-center jumbotron my-5" py-5>

View File

@ -0,0 +1,15 @@
{% extends 'base.html' %}
{% load i18n %}
{% get_current_language as LANGUAGE_CODE %}
{% block languagecode %}{{ LANGUAGE_CODE }}{% endblock languagecode %}
{% block title %}{% translate "cscherr.de" %} - {% translate "startpage" %}{% endblock title %}
{% block main %}
<div class="jumbotron text-center">
<h1>403 {% translate "Permission denied" %}</h1>
<p>{% translate "You are not allowed to access this page." %}</p>
</div>
<div class="container text-center jumbotron my-5" py-5>
<h1 class="my-4">{% translate "Looking for anything specific?" %}</h1>
{% include 'main_search_form.html' %}
</div>
{% endblock main %}

View File

@ -1,3 +1,4 @@
from django.http import HttpResponseBadRequest, HttpResponseForbidden, HttpResponseNotAllowed, HttpResponseNotFound, HttpResponseServerError
from django.shortcuts import redirect from django.shortcuts import redirect
from django.utils import translation from django.utils import translation
from django.views.generic.base import View from django.views.generic.base import View
@ -6,6 +7,7 @@ from django.views import View
from django.shortcuts import render from django.shortcuts import render
from django.views.generic.list import QuerySet from django.views.generic.list import QuerySet
from django.db.models import Q from django.db.models import Q
from django.views.static import loader
from requests import request from requests import request
from .forms import MainSearchForm from .forms import MainSearchForm
@ -110,10 +112,19 @@ def Error400(request, exception):
""" """
template_name = "errors/400.html" template_name = "errors/400.html"
data = { t = loader.get_template(template_name)
'exception': exception data = {'exception': exception}
} return HttpResponseBadRequest(t.render(data, request), content_type='application/xhtml+xml')
return render(request, template_name, data, status=400)
def Error403(request, exception):
"""
403 View, the user has been denied permission
"""
template_name = "errors/403.html"
t = loader.get_template(template_name)
data = {'exception': exception}
return HttpResponseForbidden(t.render(data, request), content_type='application/xhtml+xml')
def Error404(request, exception): def Error404(request, exception):
""" """
@ -123,10 +134,9 @@ def Error404(request, exception):
""" """
template_name = "errors/404.html" template_name = "errors/404.html"
data = { t = loader.get_template(template_name)
'exception': exception data = {'exception': exception}
} return HttpResponseNotFound(t.render(data, request), content_type='application/xhtml+xml')
return render(request, template_name, data, status=404)
def Error500(request): def Error500(request):
""" """
@ -136,6 +146,7 @@ def Error500(request):
""" """
template_name = "errors/500.html" template_name = "errors/500.html"
t = loader.get_template(template_name)
data = {} data = {}
return render(request, template_name, data, status=500) return HttpResponseServerError(t.render(data, request), content_type='application/xhtml+xml')