前言

在Flask中自定义错误页面,像404、500等。
404:客户端请求未知页面或路由时显示。
500:有未处理的异常时显示。
404页面

自定义方法

在程序实例中添加下面的代码:

@app.errorhandler(404)
def page_not_found(e):
    return render_template('404.html'), 404


@app.errorhandler(500)
def internal_server_template(e):
    return render_template('500.html'), 500

两个漂亮的错误页面

1、动态下雪特效
百度云地址:https://pan.baidu.com/s/14LD5Npg_r7wWp2LyBzkQAA 提取码: zhps

需要自己去修改html文件中的【返回首页】地址

动态下雪特效
2、简约风格
百度云地址:https://pan.baidu.com/s/1qsmEjK_cxHvwnM2ocQjEDA 提取码: famv
在static文件夹下创建images和styles文件夹,分别把png图片和css样式文件放入里面,在html文件中修改返回首页地址和站长QQ

简约风格

最后修改:2020 年 01 月 25 日
如果觉得我的文章对你有用,请随意赞赏