简体   繁体   中英

Flask : BuildError

@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']?

回溯的底部被切除,但是看起来在index.html模板中,您正在为sign路由调用url_for ,而未指定error的值。

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM