tags:

views:

53

answers:

1

I modify the login of flaskr sample app, the first line get error. But www.html is in the template dir.

return redirect(url_for('www'))
#return redirect(url_for('show_entries'))

display error:

werkzeug.routing.BuildError

BuildError: ('www', {}, None) 

Thanks for help!

+2  A: 

return redirect(url_for('www')) would work if you have a function somewhere else like this:

@app.route('/welcome')
def www():
    return render_template('www.html')

url_for looks for a function, you pass it the name of the function you are wanting to call. Think of it like this:

@app.route('/login')
def sign_in():
    for thing in login_routine:
        do_stuff(thing)
    return render_template('sign_in.html')

@app.route('/new-member')
def welcome_page():
    flash('welcome to our new members')
    flash('no cussing, no biting, nothing stronger than gin before breakfast')
    return redirect(url_for('sign_in')) # not 'login', not 'sign_in.html'

You could also do return redirect('/some-url'), if that is easier to remember. It is also possible that what you want, given your first line, is just return render_template('www.html').

bvmou
I see, really thank you bvmou veru much.
chenge
+1 for a very clear example ... and for "nothing stronger than gin before breakfast"
Sean Vieira