在运行平台进行注册请求时: 提交表单时,它不会按我的意愿重定向到主页
from flask import Flask,render_template,url_for,flash,redirect
from formapp import Regist_form, Login_form
app= Flask(__name__,template_folder='webpages')
app.config['SECRET_KEY']='6bdss5z9884s56q6662x3xdde3f'
@app.route('/')
def home():
return render_template('home.html')
@app.route('/regist',methods=['GET', 'POST'])
def regist():
form= Regist_form()
if form.validate_on_submit():
flash(f'account created for {{ form.username.data }}!' ,'success')
return redirect(url_for("home"))
# print (form.username.data)
# else:
# flash(f'account created for { form.username.data }!' ,'error')
# return redirect(url_for('home'))
return render_template('regist.html',form=form)
@app.route('/login')
def login():
form=Login_form
return render_template('login.html',form=form)
if __name__=='__main__':
app.run(debug=True)
如何解决?
答案 0 :(得分:0)
不需要url_for
来重定向...
替换此:
return redirect(url_for("home"))
为此:
return redirect("/", code=302)
code=302
告诉flask进行重定向没有问题