Skip to content

Commit

Permalink
Use a custom error handler so we have access to the request context p…
Browse files Browse the repository at this point in the history
…rocessors and render the 500 page nicely.
  • Loading branch information
jezdez committed Jul 24, 2012
1 parent 67d4a1d commit 5f1c83d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
3 changes: 3 additions & 0 deletions django_website/urls/www.py
Expand Up @@ -26,6 +26,9 @@
'flatpages': FlatPageSitemap,
}

handler500 = 'django_website.views.server_error'


urlpatterns = patterns('',
url(r'^$', 'django.views.generic.simple.direct_to_template', {'template': 'homepage.html'}, name="homepage"),
url(r'^accounts/', include('django_website.accounts.urls')),
Expand Down
14 changes: 12 additions & 2 deletions django_website/views.py
Expand Up @@ -5,10 +5,12 @@

from django.contrib.comments.models import Comment
from django.contrib.sitemaps import views as sitemap_views
from django.shortcuts import render
from django.views.decorators.cache import cache_page
from django.views.decorators.csrf import csrf_exempt
from django.views.decorators.csrf import csrf_exempt, requires_csrf_token
from django.views.generic import list_detail
from django.views.generic.simple import direct_to_template

from .sitemaps import FlatPageSitemap, WeblogSitemap

def homepage(request):
Expand All @@ -30,4 +32,12 @@ def comments(request):

@csrf_exempt
def donate_thanks(request):
return direct_to_template(request, 'donate_thanks.html')
return direct_to_template(request, 'donate_thanks.html')


@requires_csrf_token
def server_error(request, template_name='500.html'):
"""
Custom 500 error handler for static stuff.
"""
return render(request, template_name)

0 comments on commit 5f1c83d

Please sign in to comment.