[英]werkzeug.routing.BuildError using redirect url_for
Trying to pass a variable while I'm using redirect(url_for())
I face this error:在我使用
redirect(url_for())
时尝试传递变量我遇到了这个错误:
werkzeug.routing.BuildError: Could not build url for endpoint 'view'. Did you forget to specify values ['password']?
Function where I call 'view' and try to specify a value to 'password': Function 我称之为“视图”并尝试为“密码”指定一个值:
@app.route('/confirmAdmin/', methods=["GET", "POST"])
def confirmAdmin():
if request.method == "POST":
if request.form["password"] == 'pass123':
return redirect(url_for("view"), password='pass123')
View Rote:查看死记硬背:
@app.route('/view/<password>/')
def view(password):
if password == 'pass123':
return render_template("view.html", values=users.query.all())
I believe the error is on the first route, because i tried to access directly http://127.0.0.1:5000/view/pass123/ and it works normally.我相信错误出现在第一条路线上,因为我试图直接访问http://127.0.0.1:5000/view/pass123/并且它工作正常。
refer to this doc https://flask.palletsprojects.com/en/1.1.x/api/#flask.url_for请参阅此文档https://flask.palletsprojects.com/en/1.1.x/api/#flask.url_for
change this line更改此行
return redirect(url_for("view"), password='pass123')
to至
return redirect( url_for("view", password='pass123') )
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.