为什么我不能返回登录HTML页面? [英] why can't I return to login html page?
本文介绍了为什么我不能返回登录HTML页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
@app.route('/forgotpasswd/<token>',methods=['GET', 'POST'])
def forgot_passwd(token):
form = Newpasswd(request.form)
password=form.passwd.data
if request.method == "POST" and form.validate():
try:
email = secret.loads(token, salt='forgotpasswd', max_age=3600)
except SignatureExpired:
flash("Timeout","danger")
return render_template("index.html")
finally:
cursor=Mysql.connection.cursor()
sorgu = "UPDATE users set password='{}' WHERE email= '{}' ".format(password,email)
cursor.execute(sorgu)
Mysql.connection.commit()
cursor.close()
flash("password changed","success")
return redirect(url_for("login"))
return render_template("newpassword.html",form=form)
我在newpasswd.html页面上输入了新密码,并在输入新密码后将其发布,但是这使我回到了newpasswd.html页面上.我想转到login.html页面.
I enter my new password on the newpasswd.html page and post it after entering it but it throws me back on the newpasswd.html page. I want to go to the login.html page.
推荐答案
我想您需要稍微更改代码:
i guess you need to change your code little bit:
@app.route('/forgotpasswd/<token>',methods=['GET', 'POST'])
def forgot_passwd(token):
form = Newpasswd() # here, you don't need to pre populate your Form object
# with the request parameters, you need to validate first
# the request parameters
if form.validate_on_submit(): # here, since you are using Forms with flast-wft
password=form.passwd.data # here
try:
email = secret.loads(token, salt='forgotpasswd', max_age=3600)
except SignatureExpired:
flash("Timeout","danger")
return render_template("index.html")
finally:
# this block wont work if "secret.loads()" function fails to return
# the email, so add an if statement block
if email is none:
cursor=Mysql.connection.cursor()
sorgu = "UPDATE users set password='{}' WHERE email= '{}' ".format(password,email)
cursor.execute(sorgu)
Mysql.connection.commit()
cursor.close()
flash("password changed","success")
else:
flash("problem","danger")
return redirect(url_for("login"))
return render_template("newpassword.html",form=form)
这篇关于为什么我不能返回登录HTML页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文