Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Use a custom error handler so we have access to the request context p…

…rocessors and render the 500 page nicely.
  • Loading branch information...
commit 5f1c83da278a7ff2e18ca3a5fa953d1c6b2937b8 1 parent 67d4a1d
@jezdez jezdez authored
Showing with 15 additions and 2 deletions.
  1. +3 −0  django_website/urls/www.py
  2. +12 −2 django_website/views.py
View
3  django_website/urls/www.py
@@ -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')),
View
14 django_website/views.py
@@ -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):
@@ -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)
Please sign in to comment.
Something went wrong with that request. Please try again.