emmmmm,这是个悲伤的故事
最近在学pythonweb,学到了怎么从网页中的POST请求中获取数据,然后实操了一下
看着和视频中一模一样的代码,为什么我使用的时候,request.form.get()的返回值是None,视频中却是页面中输入的值呢???
以下是我的代码
<!doctype html>
<html lang="zh-cn">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>登陆系统</title>
</head>
<body>
<h1>登陆</h1>
<form method="post">
<input type="text",name="123">
<input type="password",name="pwd">
<input type="submit",value="提交">
</form>
</body>
</html>
from flask import Flask, render_template, request, redirect
app = Flask(__name__) # 创建Flask实例,固定用法
@app.route("/login", methods=["GET", "POST"]) # 路径,"/"即根目录
def hello_world(): # 路由和函数放一起
if request.method == 'GET':
return render_template('login.html')
user = request.form.get('123')
pwd = request.form.get('pwd')
print(user)
if user == 'alex' and pwd == '123':
return redirect('/index')
else:
return render_template('login.html')
@app.route("/index")
def index():
return "欢迎登陆"
于是在各种网站找资料,始终没有找到相应的问题。。
最终发现,问题出在html的代码中,我在name属性前加了','!!!!!!!!
把,删掉之后,程序正常运行,那么,为什么这个,会影响form表单中数据的传递呢?
我也不知道,等以后找到答案再来补充