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>
相关推荐
2601_948374573 分钟前
商用电子秤怎么选
大数据·python
Volunteer Technology9 分钟前
Sentinel的限流算法
java·python·算法
froginwe1117 分钟前
Python 条件语句
开发语言
七夜zippoe20 分钟前
Python统计分析实战:从描述统计到假设检验的完整指南
开发语言·python·统计分析·置信区间·概率分布
2601_9491465327 分钟前
Python语音通知API示例代码汇总:基于Requests库的语音接口调用实战
开发语言·python
去码头整点薯条9832 分钟前
python第五次作业
linux·前端·python
3GPP仿真实验室33 分钟前
【Matlab源码】6G候选波形:OFDM-IM 索引调制仿真平台
开发语言·matlab
有代理ip1 小时前
Python 与 Golang 爬虫的隐藏优势
爬虫·python·golang
数研小生1 小时前
1688商品列表API:高效触达批发电商海量商品数据的技术方案
大数据·python·算法·信息可视化·json
Coder_Boy_1 小时前
基于SpringAI的在线考试系统-企业级教育考试系统核心架构(完善版)
开发语言·人工智能·spring boot·python·架构·领域驱动