Flask : BuildError

Question:

@app.route('/sign/<error>')
def sign(error=''):
    return render_template('sign.html',er=error)
@app.route('/process', methods=['POST','GET'])
def process():
    ch = request.form['box']
    if ch == 'ok':
        name = request.form['name']
        comment = request.form['comment']

        signature = Comments(name=name, comment=comment)
        db.session.add(signature)
        db.session.commit()
        return redirect(url_for('index'))
    else :
        er='please check'
        return redirect(url_for('sign',error=er))

sign.html have this line of code

<div style="color: red;">{{er}}</div>

this is a picture for what i get
BuildError: Could not build url for endpoint ‘sign’. Did you forget to specify values [‘error’]?

Asked By: Peter Safwat

||

Answers:

The bottom of your traceback is cut off, but it looks like in your index.html template you’re calling url_for for your sign route without specifying a value for error.

Answered By: Matt Healy

Error occurred because /sign/error, error is none.
Either you can try changing def sign(error='') to def sign(error), or change er='please check' to ‘pleasecheck'(that doesn’t contain blank)

Answered By: mikky
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.