【Django】配置自定义404页面时,报错The custom handler404 view does not take the correct number of arguments

项目场景:

提示:这里简述项目相关背景:

django 3.2自定义404页面,修改了settings.pyurls.py,并编写了自定义404函数page_not_found

settings.py

DEBUG = False
ALLOWED_HOSTS = ["*"]

urls.py

from app1 import views

urlpatterns = [
    ...
]

# 404
handler404 = views.page_not_found

views.py

def page_not_found(request):
    return render(request, 'error-404.html')

问题描述

运行时,出现报错:

django.core.management.base.SystemCheckError: SystemCheckError: System check identified some issues:

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

System check identified 1 issue (0 silenced).

原因分析:

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

错误提示,自定义handler404视图未采用正确数量的参数,提示我们参数应该有两个,分别是(request, exception)

检查404函数的写法,缺少exception参数


解决方案:

修改page_not_found参数,增加一个exception

def page_not_found(request, exception=None):
    return render(request, 'error-404.html')
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值