Skip to content

Instantly share code, notes, and snippets.

@dfalk
Created December 29, 2011 07:58
Show Gist options
  • Save dfalk/1532789 to your computer and use it in GitHub Desktop.
Save dfalk/1532789 to your computer and use it in GitHub Desktop.
django 404 context
# File handlers.py
from django.shortcuts import render_to_response
from django.template import RequestContext, Context
from functools import partial
def base_error(request, template_name=None):
try:
context = RequestContext(request)
except:
context = Context()
return render_to_response(template_name, context_instance=context)
page_not_found = partial(base_error, template_name='404.html')
server_error = partial(base_error, template_name='500.html')
# Your root urls.py file should have this
handler404 = 'handlers.page_not_found'
handler500 = 'handlers.server_error'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment