Flask-Web-App-Tutorial icon indicating copy to clipboard operation
Flask-Web-App-Tutorial copied to clipboard

werkzeug.routing.BuildError

Open jvivar2383 opened this issue 2 years ago • 3 comments

I'm not sure why I keep having this issue. I check my code since I assumed the problem was in the log-out function but I'm not really sure how to fix it. This is what the rest of the message says: werkzeug.routing.BuildError: Could not build url for endpoint 'auth.login'. Did you mean 'auth.logout' instead?

this is the function I have for log out: def logout():

logout_user()
#return "<p> You're now log out!</p>" 
return redirect(url_for('auth.login')) # or 'auth.login'

please help

jvivar2383 avatar May 19 '22 23:05 jvivar2383

FYI i changed it to 'auth.logout' and still doesn't work

jvivar2383 avatar May 19 '22 23:05 jvivar2383

Do you have route above this section of code?

@auth.route('/logout') <----THIS IS THE ROUTE @login_required def logout(): logout_user() return redirect(url_for('auth.login'))

maty714 avatar May 30 '22 04:05 maty714

Hey @jvivar2383 the error occurs when it does find an route to a particular URL the auth.login points to a function named login() inside the auth object please recheck if there is any Typo error

@auth.route('/login', methods=['GET', 'POST'])
def login():
     ...
    return render_template("login.html", user=current_user)


@auth.route('/logout')
@login_required
def logout():
    logout_user()
    return redirect(url_for('auth.login'))

Hope this solved your issue

bibinthomas123 avatar Jul 14 '22 15:07 bibinthomas123