Python Flask 自定义404错误

复制代码
from flask import Flask, abort, make_response, request, render_template

app = Flask(__name__)


# 重定向到百度
@app.route('/index', methods=["GET", "POST"])
def index():
    if request.method == "GET":
        return render_template("index.html")
    if request.method == "POST":
        name = request.form.get('name')
        password = request.form.get('password')
        if name == 'zhangsan' and password == '123':
            return '登录成功'
        else:
            abort(404)


@app.errorhandler(404)
def handle_404_error(err):
    return "出现了404错误 错误信息是%s" % err


if __name__ == '__main__':
    app.run(debug=True)
相关推荐
m0_7488735515 小时前
C++与Rust交互编程
开发语言·c++·算法
ZTLJQ1 天前
序列化的艺术:Python JSON处理完全解析
开发语言·python·json
2401_891482171 天前
多平台UI框架C++开发
开发语言·c++·算法
H5css�海秀1 天前
今天是自学大模型的第一天(sanjose)
后端·python·node.js·php
阿贵---1 天前
使用XGBoost赢得Kaggle比赛
jvm·数据库·python
88号技师1 天前
2026年3月中科院一区SCI-贝塞尔曲线优化算法Bezier curve-based optimization-附Matlab免费代码
开发语言·算法·matlab·优化算法
t198751281 天前
三维点云最小二乘拟合MATLAB程序
开发语言·算法·matlab
无敌昊哥战神1 天前
【LeetCode 257】二叉树的所有路径(回溯法/深度优先遍历)- Python/C/C++详细题解
c语言·c++·python·leetcode·深度优先
m0_726965981 天前
面面面,面面(1)
java·开发语言
2401_831920741 天前
分布式系统安全通信
开发语言·c++·算法