Skip to content

Instantly share code, notes, and snippets.

@aaronlelevier
Created July 13, 2014 19:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aaronlelevier/c63613db1ec38a828c3e to your computer and use it in GitHub Desktop.
Save aaronlelevier/c63613db1ec38a828c3e to your computer and use it in GitHub Desktop.
Handle 404 and 500 errors easy with this snippet in your main Django views.py file. No urls.py configuration needed.
from django.shortcuts import render_to_response
from django.template import RequestContext
def handler404(request):
response = render_to_response('404.html', {},
context_instance=RequestContext(request))
response.status_code = 404
return response
def handler500(request):
response = render_to_response('500.html', {},
context_instance=RequestContext(request))
response.status_code = 500
return response
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment