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)
相关推荐
星越华夏15 小时前
python——三角函数用法
开发语言·python
代码中介商15 小时前
C语言数据存储深度解析:从原码反码补码到浮点数存储
c语言·开发语言·内存
gmaajt15 小时前
mysql如何检查数据库表是否存在损坏_使用CHECK TABLE命令修复
jvm·数据库·python
heRs BART15 小时前
【Flask】四、flask连接并操作数据库
数据库·python·flask
PyHaVolask16 小时前
Python 爬虫进阶:直接请求 JSON 接口与开发者工具使用
爬虫·python·请求头·反爬·json接口·chrome开发者工具
larance16 小时前
安装dify的几个问题
python
2301_7735536216 小时前
CSS如何对用户访问过的链接进行降级颜色处理_使用-visited伪类改变颜色
jvm·数据库·python
2301_8152795216 小时前
Golang怎么理解Go的sync.Pool底层_Golang如何理解Pool的本地缓存和GC清理机制【详解】
jvm·数据库·python
2301_7641505616 小时前
MySQL迁移过程如何避免数据不一致_利用强一致性备份方案
jvm·数据库·python
m0_7164300716 小时前
Redis如何处理预热失效引起的开局雪崩
jvm·数据库·python