首页 > 其他 > 详细

Django 配置404页面

时间:2019-09-11 00:29:36      阅读:432      评论:0      收藏:0      [点我收藏+]

 

修改settings.py

DEBUG = False  # 开发环境下为True,此时我们改为False
ALLOWED_HOSTS = [*]  # 访问地址,127.0.0.1,自己的ip,如172.21.21.21(随便写的),...

静态文件配置


STATIC_URL = /static/ STATIC_ROOT = os.path.join(BASE_DIR, static).replace(\\, /)

在settings.py文件目录中,添加文件view.py

# 404
def page_not_found(request, exception):
    return render(request, 404.html)

# 500
def page_error(request):
    return render(request, 500.html)

在settings.py文件目录中,修改文件urls.py

from django.conf.urls import url
from . import view

urlpatterns = [
    ...
]
handler404 = view.page_not_found
handler500 = view.page_error

可能会报错

ERRORS:
?: (urls.E007) The custom handler404 view index.views.page_not_found 
does not take the correct number of arguments (request, exception).

System check identified 1 issue (0 silenced).

说明接口函数少传了一个参数

 

 

参数:

https://blog.csdn.net/geek_xiong/article/details/90349476

https://www.cnblogs.com/tynam/archive/2018/12/26/10182462.html

https://blog.csdn.net/u010429424/article/details/77363531

https://blog.csdn.net/liyyzz33/article/details/85259744

 

Django 配置404页面

原文:https://www.cnblogs.com/sea-stream/p/11503943.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!