junior
junior

Reputation: 496

werkzeug.routing.BuildError using redirect url_for

Trying to pass a variable while I'm using redirect(url_for()) I face this error:

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':

@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.

Upvotes: 0

Views: 79

Answers (1)

cizario
cizario

Reputation: 4269

refer to this doc 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') )

Upvotes: 1

Related Questions