Flask - redirect url_for Error

user2104391 picture user2104391 · Mar 14, 2013 · Viewed 21.4k times · Source

Am having errors thrown in my flask application for the below Code.

@@app.route('/')
.....

return redirect(url_for('nextPage'),id=DBTable.id)


@app.route('/<path:id>')
@login_required
def nextPage(id):
return render_template('page2.html')               

Error - 
---------------------------------------------------------------------------
File "C:\Python27\lib\site-packages\werkzeug\routing.py", line 1607, in build
raise BuildError(endpoint, values, method)
BuildError: ('nextPage', {}, None)
<SocketIOServer fileno=116 address=0.0.0.0:5000>: Failed to handle request:
request = POST /landingPage HTTP/1.1 from ('127.0.0.1', 50287)
application = <flask.app.Flask object at 0x0000000002643B70>

Kindly help me with the above issue

Answer

Teisman picture Teisman · Mar 14, 2013

Besides all the obvious syntax errors, the problem should be resolved by placing the arguments that you pass to the route within the url_for block.

@app.route('/')
def index():
    # ...
    return redirect(url_for('nextPage', id=DBTable.id))

@app.route('/<id>')
def nextPage(id):
    # ...
    return render_template('page2.html')