django配置错误404页面
- 准备好404.html页面。内容普通html格式内容
哎呦!出错啦。攻城狮在加班加点抢修中…
100011111101100111001100010111100110100001100000011010010011000011101011001011101100010
- 在主项目配置文件settings.py文件更改内容和配置templates文件夹
DEBUG = False
ALLOWED_HOSTS = [’*’]
‘DIRS’: [os.path.join(BASE_DIR, ‘templates’)]
- 在app应用中的views.py 中添加视图函数
from django.shortcuts import render_to_response
def page_not_found(request):
return render_to_response(‘404.html’)
- 在app应用中的urls.py添加引用
from . import views
handler404 = views.page_not_found
- 重启项目输入错误的url测试