Python Flask 表单的使用

新建templ;ates/index.html 内容如下

复制代码
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<form action="">
    账号:

    <input type="text" name="name">
    <br>
    密码:
    <input type="password" name="password">
    <br>
    <input type="submit" name="submit">
</form>

</body>
</html>

在

针对这个templates目录需要做一下模板设置

选择 jinja2

新建 main_from.py

复制代码
main_form.py

from flask import Flask, render_template

app = Flask(__name__)

@app.route('/index')
def index():
    return render_template("index.html")


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

效果

如果针对post提交可以修改

main_from.py代码

复制代码
@app.route('/index',methods=['GET',"POST"])

和修改index.html

复制代码
<form action="" method="post">
    账号:
    <input type="text" name="name">
    <br>
    密码:
    <input type="password" name="password">
    <br>
    <input type="submit" name="submit">
</form>
相关推荐
raindayinrain14 分钟前
c++高性能--原子操作,无锁编程,操作顺序
开发语言·c++·性能优化
梯度下降者18 分钟前
零基础入门Python 爬虫
爬虫·python·数据分析·入门指南·webcrawler
学逆向的23 分钟前
C++ 合并命名空间
开发语言·c++·网络安全
Zhao-Jichao29 分钟前
VS2026 打包 C++ 程序生成 EXE,借助 Installer Project 扩展工具
开发语言·c++
学逆向的1 小时前
C 局部静态变量
c语言·开发语言·网络安全
大都督会赢的2 小时前
C++第一节课
开发语言·c++
“AI国潮设计-小江”2 小时前
【AIGC实战】Python+Stable Diffusion打造“英歌舞财神”IP,解锁“马到成功”等爆款情绪营销文案设计
开发语言·人工智能·python·prompt·aigc
小王C语言2 小时前
Qt常用控件:容器类控件,标题分组框、标签页(浏览器标签)
开发语言·qt
我是唐青枫3 小时前
Kotlin Delegation 委托详解
开发语言·kotlin
qq_406981033 小时前
共享变量一 关于extern与const
开发语言·c++