环境同前一篇django文章。
启动web服务:cd /root/py3/django-test1/test3/
python manage.py runserver 192.168.255.70:8000
当访问不存在的页面时,自定义404页面提供给客户端。
注意:定义html模板时,必须在主配置文件settings.py中添加模板路径,和相应配置:vim /root/py3/django-test1/test3/test3/settings.py
DEBUG = False
ALLOWED_HOSTS = [*]
TEMPLATES = [
{
...
'DIRS': [os.path.join(BASE_DIR,'templates')],
...
}
创建404.html文件:vim templates/404.html
HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://×××w.w3.org/TR/html4/loose.dtd">
Title{{ request_path }}
this is page self definte 404
完成自定义404页面的访问。