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>
相关推荐
Flying_Fish_roe15 分钟前
Spring Boot-RESTful API相关问题
spring boot·python·restful
day3ZY20 分钟前
清理C盘缓存,电脑缓存清理怎么一键删除,操作简单的教程
c语言·开发语言·缓存
学地理的小胖砸32 分钟前
【高分系列卫星简介】
开发语言·数码相机·算法·遥感·地理信息
码农豆豆34 分钟前
4.C++中程序中的命名空间
开发语言·c++
怀九日37 分钟前
C++(学习)2024.9.19
开发语言·c++·学习·重构·对象·
叫我:松哥1 小时前
基于机器学习的癌症数据分析与预测系统实现,有三种算法,bootstrap前端+flask
前端·python·随机森林·机器学习·数据分析·flask·bootstrap
KookeeyLena81 小时前
如何限制任何爬虫爬取网站的图片
开发语言·c++·爬虫
我是瓦力1 小时前
球形包围框-Bounding Sphere-原理-代码实现
人工智能·python·深度学习·计算机视觉·3d
yanyanwenmeng1 小时前
matlab基础
开发语言·算法·matlab
拉玛干1 小时前
社团周报系统可行性研究-web后端框架对比-springboot,django,gin
数据库·python·spring·golang