Custom Django 404 error

django, http-status-code-404

Solution

This worked for me:

from django.conf.urls import patterns, include, url
from django.views.static import * 
from django.conf import settings
from django.conf.urls.defaults import handler404, handler500
from app.views import error

urlpatterns = patterns('',
    # Examples:
    # url(r'^$', 'app.views.home', name='home'),
)

handler404 = error.error_handler
handler500 = error.error_handler

You can make it do anything as you wish when going to that controller.

Problem

I have a 404.html page, but in some cases I want to be able to send a json error message (for 404 and 500, etc.). I read the following page: https://docs.djangoproject.com/en/dev/topics/http/views/#the-404-page-not-found-view Is there any sort of example that shows the implementation? I have it in my urls.py but it's not being picked up in the event of an error.

Original source