Skip to content

Instantly share code, notes, and snippets.

@ijmorgado
Created April 6, 2013 05:56
Show Gist options
  • Save ijmorgado/5325047 to your computer and use it in GitHub Desktop.
Save ijmorgado/5325047 to your computer and use it in GitHub Desktop.
This is a small definition of custom error 404 page (Not found) on a Django view... With this kind of definition we're using a http class to generate a response by passing a RequestContext...I know...it can be done with just 1 line in the body on the function but this is another way...and could be useful for someone :=)
# ...imports and other stuff....
# This is really important when we set DEBUG = False on settings.py to define custom error pages....
handler404 = 'my_app_name.views.not_found_404'
handler500 = 'my_app_name.views.internal_error_500'
# ...urlpatterns and another stuff....
from django.template import RequestContext, loader
from django import http
def not_found_404(request, template_name='system/not_found.html'):
t = loader.get_template(template_name)
return http.HttpResponseNotFound(t.render(RequestContext(request,{'request_path': request.path})))
def internal_error_500(request):
return render(request, 'system/internal_error.html') # as you can see...this is another way to call a template for a view...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment