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>
相关推荐
陈年老古董9 小时前
OpenCV图像处理笔记:图像拼接、答题卡识别与目标提取
人工智能·笔记·python·opencv·计算机视觉
深念Y9 小时前
为什么选 Go:直观、可维护、AI 友好
linux·开发语言·人工智能·golang·agent·harness
Billy121389 小时前
Day25-编译期计算与 constexpr if:跨越编译与运行的边界
开发语言·c++进阶学习
CTA终结者9 小时前
2026年程序员量化开发学习:用示例、拆解和练习入门
人工智能·python
小酒星小杜9 小时前
如何简单地创建你的第一部漫画?从一个“可见变化”开始
人工智能·python·产品
sel_99 小时前
【OPD论文导读(二)】OPD(On-Policy Distillation)全景调研:十篇论文讲透“在自己生成的内容上学习“这件事
人工智能·python·深度学习·学习·算法·语言模型
北山小恐龙10 小时前
使用手势在电脑刷抖音
人工智能·python·深度学习·yolo·机器学习·计算机视觉
小小龙学IT10 小时前
第七节 C++ 与 QML 交互
开发语言·qt
晓晓_za89866810 小时前
Geo 优化源码二次开发:自定义地域规则改造实操文档
java·开发语言·搜索引擎·ci/cd·矩阵