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>
相关推荐
圆圆讲门店6 小时前
实体获客团队|基础概念与核心要点整理
人工智能·python
uoKent6 小时前
c++中的extern关键字
开发语言·c++
牧杉-惊蛰6 小时前
将数组对象根据自定义排列
java·开发语言·算法
砚底藏山河7 小时前
【量化纯GET实战 #04】批量快照:一次 HTTP GET 取多只股票
java·python·金融·eclipse
君顾17 小时前
家校托管互通:从需求分析到系统架构的落地实践
java·开发语言·托管
烂蜻蜓7 小时前
Flask入门教程(九):模板渲染——用Jinja2构建动态页面
后端·python·flask
2601_966871407 小时前
AE影视后期特效-遮罩/调色/抠像/MG动画/3D/Vlog制作(完结)jzit
python
jimy17 小时前
c++隐式移动构造、强制拷贝省略、返回具名局部变量
开发语言·c++
circuitsosk7 小时前
大模型本体安全防护实践:提示词注入防御、输出合规过滤与敏感信息脱敏
python·安全·数据脱敏·纵深防御·提示词注入·llmsecurity
v_for_van7 小时前
C语言__attribute__
服务器·c语言·开发语言·mcu·嵌入式·嵌入式实时数据库