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文件即可。

相关推荐
西柚研究生12345613 分钟前
论文分析17:YOLOv11_UAVNet:无人机航拍图像专用目标检测算法
人工智能·python·深度学习·算法·目标检测
RAN114267600822 分钟前
1.3第一个程序的介绍
开发语言·qt
沧海一笑-dj1 小时前
【Python】Python学习笔记-初识 Python
python·python安装·python解释器
打工仔折腾 AI1 小时前
FastAPI 从本机到生产服务器:Nginx+Gunicorn+Uvicorn 完整部署实录
人工智能·后端·python·nginx·fastapi·gunicorn
blue_ice .1 小时前
Verilog DDS 数字信号发生器:DAC 输出模拟波形与 ADC 回采观测
开发语言·单片机·嵌入式硬件·fpga开发
hanchenxing1 小时前
AI 数据管道重构:从函数堆到链式管道的可读性实践
python
hhzz1 小时前
【OpenCV 入门到精通 10】视频分析与光流跟踪:背景减除与运动检测
人工智能·python·opencv·性能优化
蓝胖的四次元口袋1 小时前
Python基础语法入门
python
远翔调光芯片^138287988721 小时前
ECP5702能芯科技PD取电芯片在市场上的优势有哪些?
开发语言·人工智能·单片机·嵌入式硬件·智能家居
Patrick在香港1 小时前
Python 抓 0.91 GB 香港法例:Agent 的进度该写进磁盘,不是写进上下文
爬虫·python·api·claude·香港