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

相关推荐
前端付豪2 小时前
AI 数学辅导老师项目构想和初始化
前端·后端·python
用户0332126663672 小时前
将 PDF 文档转换为图片【Python 教程】
python
悟空爬虫3 小时前
UV实战教程,我啥要从Anaconda切换到uv来管理包?
python
dev派3 小时前
AI Agent 系统中的常用 Workflow 模式(1)
python·langchain
明月_清风5 小时前
从“能用”到“专业”:构建生产级装饰器与三层逻辑拆解
后端·python
曲幽15 小时前
数据库实战:FastAPI + SQLAlchemy 2.0 + Alembic 从零搭建,踩坑实录
python·fastapi·web·sqlalchemy·db·asyncio·alembic
用户83562907805119 小时前
Python 实现 PowerPoint 形状动画设置
后端·python
ponponon21 小时前
时代的眼泪,nameko 和 eventlet 停止维护后的项目自救,升级和替代之路
python
Flittly21 小时前
【从零手写 ClaudeCode:learn-claude-code 项目实战笔记】(5)Skills (技能加载)
python·agent
敏编程21 小时前
一天一个Python库:pyarrow - 大规模数据处理的利器
python