常见的出错模板有:
404.html : [page not found] 页面未找到……
500.html : [server error] 内部错误……
403.html : [HTTP Forbidden] 禁止访问……
400.html : [bad request] 页面已删除、更名、过期或暂不可用……
修改如下:
settings.py
ALLOWED_HOSTS = ['0.0.0.0' , ] #debug = True
urls.py
from django.conf.urls import url , include from django.contrib import admin import audios handler404 = 'audios.views.my_custom_page_not_found_view' #HttpResponseNotFound handler500 = 'audios.views.my_custom_error_view' handler403 = 'audios.views.my_custom_permission_denied_view' # HttpResponseForbidden handler400 = 'audios.views.my_custom_bad_request_view' urlpatterns = [ url(r'^admin/', admin.site.urls), url(r'^audios/', include('audios.urls')), ]
$ tree templates/custom/ templates/custom/ ├── 400.html ├── 403.html ├── 404.html └── 500.html
audios/views.py
def my_custom_page_not_found_view(request): return render_to_response('custom/404.html') def my_custom_error_view(request): return render_to_response('custom/500.html') def my_custom_permission_denied_view(request): return render_to_response('custom/403.html') def my_custom_bad_request_view(request): return render_to_response('custom/400.html')
DONE DONE DONE