custom error pages
This commit is contained in:
parent
011c967446
commit
4c7f60fab7
|
@ -29,11 +29,3 @@ urlpatterns += i18n_patterns(
|
|||
path("blog/", include("blog.urls")),
|
||||
path('admin/', admin.site.urls, name="admin"),
|
||||
)
|
||||
|
||||
# use my fancy error pages
|
||||
# better yet, don't let it come to that
|
||||
# FIXME these break the server. something is wrong with them
|
||||
handler400 = 'start.views.Error400'
|
||||
handler403 = 'start.views.Error403'
|
||||
handler404 = 'start.views.Error404'
|
||||
#handler500 = 'start.views.Error500'
|
||||
|
|
|
@ -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>400 {% translate "Bad request" %}</h1>
|
||||
<p>{% translate "You sent bad data to the server." %}</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 %}
|
|
@ -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 %}
|
|
@ -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>404 {% translate "Not found" %}</h1>
|
||||
<p>{% translate "The resource you are looking for does not exist." %}</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 %}
|
|
@ -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>500 {% translate "Internal Server Error" %}</h1>
|
||||
<p>{% translate "Something went wrong." %}</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 %}
|
|
@ -15,6 +15,9 @@ from .models import Link, Searchable
|
|||
|
||||
from abc import ABC
|
||||
|
||||
import logging
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
class SearchableView(View, ABC):
|
||||
"""
|
||||
This abstract view implements some traits of views that should show up
|
||||
|
@ -105,48 +108,3 @@ class Links(ListView):
|
|||
)
|
||||
object_list = object_list.filter(public=True)
|
||||
return object_list
|
||||
|
||||
def Error400(request, exception):
|
||||
"""
|
||||
400 View, the user did some bad request.
|
||||
"""
|
||||
|
||||
template_name = "errors/400.html"
|
||||
t = loader.get_template(template_name)
|
||||
data = {'exception': exception}
|
||||
return HttpResponseBadRequest(t.render(data, request), content_type='application/xhtml+xml')
|
||||
|
||||
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):
|
||||
"""
|
||||
404 View, whatever you are looking for does not exist.
|
||||
|
||||
Officially at least, might also mean that it does not exist for you
|
||||
"""
|
||||
|
||||
template_name = "errors/404.html"
|
||||
t = loader.get_template(template_name)
|
||||
data = {'exception': exception}
|
||||
return HttpResponseNotFound(t.render(data, request), content_type='application/xhtml+xml')
|
||||
|
||||
def Error500(request):
|
||||
"""
|
||||
500 View, internal server error
|
||||
|
||||
That probably means I programmed something badly
|
||||
"""
|
||||
|
||||
template_name = "errors/500.html"
|
||||
t = loader.get_template(template_name)
|
||||
data = {}
|
||||
return HttpResponseServerError(t.render(data, request), content_type='application/xhtml+xml')
|
||||
|
||||
|
|
Loading…
Reference in New Issue