亲切的支持,我认为从html表单返回错误的值是因为我输入了sqlite数据库中已经存在的正确用户名,并且比较未成功执行并返回None值,这导致第一个条件并且无法通过达到以下第二种条件。
@app.route("/login", methods=["GET", "POST"])
def log():
if request.method == "POST":
un = request.form.get("user_name")
pss = request.form.get("pass")
conn = sqlite3.connect('Reg.db')
c = conn.cursor()
user_data = c.execute("select username from users where username=:u", {'u': un, }).fetchone()
user_pass = c.execute("select pass from users where username =:u", {'u': un, }).fetchone()
if user_data is None:
flash("Wrong Username", "danger")
return render_template("login.html")
else:
if user_pass == ('123',):
flash("You're logged in", "success")
return redirect(url_for('photo'))
else:
flash("Wrong password", "danger")
return render_template("login.html")
return render_template("login.html")