在检查用户名和密码后,我在路由到网页时遇到问题,如果输入长用户名和密码,它会显示:“列表索引超出范围”。在我的数据库中只有一个用户(我手动创建的管理员用户)。我试着只在这方面的工作,它工作后,我将在登记工作。你知道吗
这是转发到登录页的代码:
@app.route('/login', methods=['GET', 'POST'])
def login():
return render_template("login.html")
这是检查登录凭据的代码:
@app.route('/logincheck', methods=['GET', 'POST'])
def logincheck():
error = None
checkP = g.db.execute('select pword from users where uname = ?', (request.form['username'], ))
arrayCheck = checkP.fetchall()
if request.method == 'POST':
if request.form['password'] != arrayCheck[[0][0]]:
error = 'Username or password is incorrect'
return redirect(url_for('login'))
if len(arrayCheck) == 0:
error = 'Username or password is incorrect'
return redirect(url_for('login'))
else:
session['logged_in'] = True
flash('You are logged in')
return redirect(url_for('userpage'))
return render_template('login.html')
在html文件中“登录.html“我有一个表单转发到/logincheck,logincheck转发到userpage,这是网站本身。你知道吗
目前没有回答
相关问题 更多 >
编程相关推荐