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)
相关推荐
杨充4 小时前
05.多用组合和少继承
开发语言·bash
今天AI了吗4 小时前
从聊天到委派:AI Agent 如何推进长期任务
数据库·人工智能·python·sql·rust
傻啦嘿哟4 小时前
王者荣耀爬虫:爬取全英雄皮肤数据,用Python做可视化分析
开发语言·爬虫·python
AI直播技术杂谈4 小时前
直播画面突然模糊了,排查了三个小时
开发语言·php
徒慕风流4 小时前
激光雷达回波信号滤波与时刻鉴别算法:原理、代码实现与仿真验证
python·算法·激光雷达
菜冻鱼4 小时前
Python-pytorch-数据加载
开发语言·人工智能·pytorch·python·深度学习·机器学习
you鬰4 小时前
datawhale--llm-algo-leetcod1️⃣
python·datawhale
heimeiyingwang4 小时前
【架构实战】可观测性三支柱实战:Metrics、Logging、Tracing 如何统一落地
开发语言·架构·php
caimouse5 小时前
ReactOS 图形系统分析(53):系统库存对象 — stockobj.c
c语言·开发语言·spring
南京云森杉木桩5 小时前
水利木桩源头直供,质量可靠价格更优
大数据·python