Custom error views to load dpaste error templates.

This commit is contained in:
Martin Mahner 2013-03-19 14:18:43 +01:00
parent 82622db10c
commit 11b582cc6c
2 changed files with 15 additions and 1 deletions

View file

@ -10,3 +10,7 @@ urlpatterns = patterns(
url(r'^', include('dpaste.urls.dpaste_api')), url(r'^', include('dpaste.urls.dpaste_api')),
url(r'^', include('dpaste.urls.dpaste')), url(r'^', include('dpaste.urls.dpaste')),
) )
# Custom error handlers which load `dpaste/<code>.html` instead of `<code>.html`
handler404 = 'dpaste.views.page_not_found'
handler500 = 'dpaste.views.server_error'

View file

@ -7,6 +7,9 @@ from django.core.exceptions import ObjectDoesNotExist, MultipleObjectsReturned
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
from django.utils import simplejson 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.forms import SnippetForm, UserSettingsForm
from dpaste.models import Snippet from dpaste.models import Snippet
@ -177,3 +180,10 @@ def guess_lexer(request):
code_string = request.GET.get('codestring', False) code_string = request.GET.get('codestring', False)
response = simplejson.dumps({'lexer': guess_code_lexer(code_string)}) response = simplejson.dumps({'lexer': guess_code_lexer(code_string)})
return HttpResponse(response) 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)