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>
相关推荐
外收内放8 小时前
Python基础语法练习题(53-54)
python·学习
聪明蛋子哟8 小时前
Python与Java双栈实战:手撸一个支持RAG与Tool Calling的高性能Agent框架
java·开发语言·python
谢亮_vipxieliang8 小时前
Go Context 控制协程生命周期
开发语言·golang
xuxigifxfh8 小时前
HJ4 字符串分隔
java·开发语言·华为机考
databook8 小时前
什么是范数?用 NumPy 动手算一遍就明白了
python·数学·numpy
MayZork9 小时前
Qt 开发集成CMake + vcpkg
开发语言·c++·qt
朝朝辞暮i9 小时前
VLA 系统学习第 5 课:神经网络的参数到底是什么?——从 nn.Linear 真正理解 W、 b 和 Gradient
人工智能·python·深度学习·神经网络·vla
XZ-0700019 小时前
week7-文本
python
零基础1239 小时前
PDF 处理工具全攻略:pdf24、PDFgear、Adobe Acrobat DC 与 Stirling-PDF 深度对比
java·开发语言·pdf
Java后端的Ai之路9 小时前
01-React基础教程
开发语言·前端·python·react.js·前端框架