[英]request.args.get() returns None
I am trying to check the users input on my login form.我正在尝试检查用户在我的登录表单上的输入。 I am sending an HTTP request to the server to check the database for the username.
我正在向服务器发送 HTTP 请求以检查数据库中的用户名。 Here is the network URL: https://bceec5a5-eba3-49e3-b255-d3976d185fad-ide.cs50.xyz:8080/user_name?username=fabianomobono
这里是网络URL: https://bceec5a5-eba3-49e3-b255-d3976d185fad-ide.cs50.xyz:8080/user_name?username=
Here's the html这是 html
<form id="login_form" action='/home' method='post'>
<input id="login_credentials_username" name='login_username' type='text' placeholder='Username' >
<input id="login_credentials_password" name='login_password' type='password' placeholder="Password" >
<button class="btn btn-primary" type='submit'>Log in</button>
</form>
This is the JS code:这是JS代码:
$('#login_form').ready(function() {
$('#login_form').on('submit', function(e) {
e.preventDefault();
logincheck();
});
});
function logincheck(){
var username = document.getElementById("login_credentials_username").value;
var password = document.getElementById("login_credentials_password").value;
if (username == ''){
alert("no user");
return false;
}
else if (password == ''){
alert('no password');
return false;
}
else if (password && username){
alert(password + username);
console.log(username)
$.get('/user_name?username' + username, function(r){
if (r === false){
alert('python returned false');
return false;
}
else{
alert('python returned true');
return true;
}
});
return false;
}
else {
return true;
}
}
and here is the python function:这是 python function:
@app.route("/user_name", methods=["GET"])
def login_usercheck():
print(Fore.GREEN + "user_check function, line 171")
username = (request.args.get('login_username'),)
print(username)
conn = sqlite3.connect('database.db')
c = conn.cursor()
c.execute("SELECT username FROM users WHERE username =?", username)
old_user = c.fetchall()
if len(old_user) > 0:
return jsonify(True)
else:
return jsonify(False)
The problem is that my username variable in the python function always returns NULL.问题是我在 python function 中的用户名变量总是返回 NULL。 I tried all combinations of,(request.form.get, request.args.get... and so on) Funny thing is I have a similar function to check for the register credentials and that one works just fine.
我尝试了所有组合,(request.form.get,request.args.get...等等)有趣的是,我有一个类似的 function 来检查注册凭据,并且那个工作得很好。 I can't seem to figure out what the problem is... Here's what I get in the terminal:
我似乎无法弄清楚问题是什么......这是我在终端中得到的:
(None,) 192.168.164.98 - - [05/Nov/2019 17:54:01] "GET /user_name?username=cf HTTP/1.0" 200 - (无,)192.168.164.98 - - [05/Nov/2019 17:54:01] “GET /user_name?username=cf HTTP/1.0”200 -
username = request.args.get(' username ')用户名 = request.args.get('用户名')
$.get('/user_name? username ' + username,... the bold parts need to match it was pointed out to me by another user... $.get('/user_name? username ' + username,...粗体部分需要匹配它是由另一个用户向我指出的...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.