From 11b582cc6c39a3b03ed09104eadef96c834ce3ad Mon Sep 17 00:00:00 2001 From: Martin Mahner Date: Tue, 19 Mar 2013 14:18:43 +0100 Subject: [PATCH] Custom error views to load dpaste error templates. --- dpaste/urls/__init__.py | 4 ++++ dpaste/views.py | 12 +++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/dpaste/urls/__init__.py b/dpaste/urls/__init__.py index 595590a..ee31aae 100644 --- a/dpaste/urls/__init__.py +++ b/dpaste/urls/__init__.py @@ -10,3 +10,7 @@ urlpatterns = patterns( url(r'^', include('dpaste.urls.dpaste_api')), url(r'^', include('dpaste.urls.dpaste')), ) + +# Custom error handlers which load `dpaste/.html` instead of `.html` +handler404 = 'dpaste.views.page_not_found' +handler500 = 'dpaste.views.server_error' \ No newline at end of file diff --git a/dpaste/views.py b/dpaste/views.py index a3a7258..383ccf8 100644 --- a/dpaste/views.py +++ b/dpaste/views.py @@ -1,12 +1,15 @@ from django.shortcuts import render_to_response, get_object_or_404, get_list_or_404 from django.template.context import RequestContext from django.http import Http404, HttpResponseRedirect, HttpResponseBadRequest, \ - HttpResponse, HttpResponseForbidden + HttpResponse, HttpResponseForbidden from django.conf import settings from django.core.exceptions import ObjectDoesNotExist, MultipleObjectsReturned from django.utils.translation import ugettext_lazy as _ from django.core.urlresolvers import reverse from django.utils import simplejson +from django.views.defaults import page_not_found as django_page_not_found, \ + server_error as django_server_error + from dpaste.forms import SnippetForm, UserSettingsForm from dpaste.models import Snippet @@ -177,3 +180,10 @@ def guess_lexer(request): code_string = request.GET.get('codestring', False) response = simplejson.dumps({'lexer': guess_code_lexer(code_string)}) return HttpResponse(response) + + +def page_not_found(request, template_name='dpaste/404.html'): + return django_page_not_found(request, template_name) + +def server_error(request, template_name='dpaste/500.html'): + return django_server_error(request, template_name)