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>
相关推荐
Petrichor_H_4 分钟前
DAY 31 文件的规范拆分和写法
python
怪兽201433 分钟前
fastjson在kotlin不使用kotlin-reflect库怎么使用?
android·开发语言·kotlin
ClearLiang33 分钟前
Kotlin-协程的挂起与恢复
开发语言·kotlin
彭同学学习日志38 分钟前
Kotlin Fragment 按钮跳转报错解决:Unresolved reference ‘floatingActionButton‘
android·开发语言·kotlin
海域云赵从友43 分钟前
破解跨境数据传输瓶颈:中国德国高速跨境组网专线与本地化 IP 的协同策略
开发语言·php
咚咚王者1 小时前
人工智能之编程进阶 Python高级:第九章 爬虫类模块
开发语言·python
深蓝海拓1 小时前
使matplot显示支持中文和负号
开发语言·python
AntBlack2 小时前
AI Agent : CrewAI 简单使用 + 尝试一下股票分析
后端·python·ai编程
一眼万里*e2 小时前
搭建本地deepseek大模型
python
1***Q7842 小时前
PyTorch图像分割实战,U-Net模型训练与部署
人工智能·pytorch·python