对flask的学习
2024-10-21 13:41:23
任务需求:一个登录,注册页面
任务环境:pycharm 2018 专业版,python3.7,win 10专业版
-----------------------------------------------------------------------------------------------------------------------------------------------------------------
前端页面 ,比较简单,自己随便做的,能传进参数就好,还没有和前端的人正式交接
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<form action="{{ url_for('login')}}" method="post">
用户:<input type="text" name = 'uname'>
密码: <input type="password" name = "upwd">
<input type="submit" value="提交">
</form>
</body>
</html>
--------------------------------------------------------
后端的py,先写一个注册页 ,有空再把数据库整理整理给上线了
#先导入数据库
from flask import Flask ,request ,render_template
app = Flask(__name__)
#对flask进行一个初始化
@app.route('/')
def index():
return "这是一个首页"
@app.route('/login/', methods=['POST' ,'GET'])
def login():
if request.method == "POST":
user = request.form.get('uname')
pwd = request.form.get('upwd')
return ("user = %s , pwd = %s " % (user , pwd))
if request.method == 'get':
return "这个请求方式不是post"
@app.route('/login1/')
def login_html():
return render_template('login.html')
if __name__ == '__main__':
app.run(debug = True)
这里选中的是post参数,在Python中接受参数会是一个 request.form.get("前端name属性的值")
get 方式提交的化,在python中接受参数会是一个request.args.get("前端name属性的值")
很多人为什么写不对post提交方式,因为python在对request.method 验证的比较好,要是小写的post就会使不正确的 。必须是大写的
if request.method == "POST":
最新文章
- NOIP2016之反面教材提供
- Ext Js【Hello World】 ——4.1 beta 1
- postgresql数据类型转换
- Java-如何挖取某个网站中的ajax请求信息
- c# TCPclient
- shell script创建库
- PD生成oracle表名带引号解决方案
- C#读取数据库返回泛型集合(DataSetToList)
- thinkphp5踩坑之部署到服务器模板不存在
- poj2635 同余定理 + 素数筛法
- ";贪吃蛇";-css3效果
- sshpass 使用方法
- 为什么不要使用 select * from xxx (oracle 亲测)
- cnn 滤波
- linux动态查看某组进程状态的办法
- ";strcmp()"; Anyone? UVA - 11732(trie出现的次数)
- 无线路由MAC地址过滤安全可靠性讨论
- python常用命令—windows终端查看安装包信息
- C++中的config设计
- MATLAB之画确定区域内不重合的随机圆
热门文章
- 万字长文,详解推荐系统领域经典模型FM因子分解机
- 如何使用 gitlab 或 github 执行npm run build
- python类继承中构造子的调用
- <;摘自>;飞:jxl简析2 [ http://www.emlog.net/fei ]
- [MIT6.006] 5. Binary Search Trees, BST Sort 二分搜索树,BST排序
- Socket 连接错误及原因
- leetcode bitmap系列问题整理
- MTK官方SDK包编译openwrt
- linux文件的3个时间和7种文件类型
- Redis在springboot项目的使用