python实现Flask POST Demo

数据处理逻辑

python 复制代码
from flask import Flask, request

app = Flask(__name__)


@app.route('/', methods=['POST'])
def index():
    username = request.form['username']
    password = request.form['password']
    if username == "Jhon" and password == "1":
        return f"<html><body>Welcome {username}</body></html>"
    else:
        return f"<html><body>Welcome!</body></html>"


if __name__ == '__main__':
    app.run(debug=True)

前端代码

html 复制代码
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>GET and POST</title>
</head>
<body>
    <form action = "http://localhost:5000" method = "post">
         <table>
            <tr>
                <td>Name</td>
                <td><input type ="text" name ="username"></td>
            </tr>
            <tr>
                <td>Password</td>
                <td><input type ="password" name ="password"></td>
            </tr>
            <tr>
                <td><input type = "submit"></td>
            </tr>
        </table>
    </form>
</body>
</html>

两个文件在同目录下,运行py文件即可。

相关推荐
夏幻灵5 小时前
JavaScript this 面试:五种绑定规则、优先级与常见面试陷阱
开发语言·javascript·面试
程序猿编码5 小时前
榨干 RTX5090 算力!Qwen3 专用单卡推理引擎,手写C++/CUDA 算子实现 MTP 推测解码
开发语言·c++·大模型推理·qwen3·多模态推理
bkspiderx7 小时前
Qt 插件机制:动态扩展应用功能的核心框架
开发语言·qt·元数据·qt 插件·qpluginloader
程序员老陆7 小时前
深入理解 C++ thread_local:线程私有存储的正确打开方式
开发语言·c++·程序设计
沐晓时光7 小时前
C语言入门,深入理解指针(3)
c语言·开发语言
码云数智-园园8 小时前
unique_ptr 还是 shared_ptr?C++ 智能指针选型与内存泄漏实战分析
java·开发语言
禾小西8 小时前
07丨Redis 哨兵机制:主库故障后,如何恢复服务?
java·开发语言·redis
我不是阵雨8 小时前
JDK 21虚拟线程Pinning陷阱:一文拔钉解困
java·开发语言
全栈练习生9 小时前
AI Agent 沙箱
python·ai
徐小黑ACG9 小时前
Golang 基础05 结构体struct
开发语言·算法·golang