在我在某些比较中使用该值之前,我试图打印出一个表单字段的值来进行一些调试。但价值总是空的。为什么这不起作用?
@app.route('/', methods=['GET', 'POST'])
def login():
username = ''
password = ''
if request.method == 'GET':
return render_template('test.html')
elif request.method == 'POST':
username == request.form.get('username')
password == request.form.get('password_data')
print password
<!DOCTYPE html>
<html>
<head>
<title>Testing</title>
</head>
<body>
<form method="post" >
<input type="text" name="username" required/>
<input type="password" placeholder ="enter Your Password" name="password_data" required/>
<input type="submit" name="signme" value="Submit"/>
</form>
</body>
</html>
答案 0 :(得分:3)
您在密码字段中使用了相等(==
)而不是赋值(=
)。因此,您实际上并未从您指定的初始空字符串password
更改''
。
password = request.form.get('password_data')
print(password)