Custom Django 404 error

前端 未结 3 1349
时光取名叫无心
时光取名叫无心 2020-12-31 14:04

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.djangoproje

3条回答
  •  执笔经年
    2020-12-31 14:55

    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.

提交回复
热议问题