werkzeug.routing.BuildError: Could not build url for endpoint 'success'. Did you forget to specify values ['name']?
Have a look at this. In your login function I added a render_template for the first GET request when opening the login page. This will probably also prevent the error you're getting now. Bear in mind this does not contain any error handling, like what happens if user is unknown in your login procedure.
@app.route('/success/<name>')
def success(name):
return 'welcome %s' % name
@app.route('/login', methods=['POST', 'GET'])
def login():
if request.method == 'POST':
user = request.form['nm']
return redirect(url_for('success', name = user))
return render_template(login.html)
if __name__ == "__main__":
app.run(debug=True)
You need to add in the else section (GET), the html code for your login.
from flask import Flask, request, render_template, redirect, url_for
app = Flask(__name__)
@app.route('/success/<name>')
def success(name):
return 'welcome %s' % name
@app.route('/login',methods = ['POST', 'GET'])
def login():
if request.method == 'POST':
user = request.form['nm']
return redirect(url_for('success',name = user))
else:
return render_template('login.html')
if __name__ == '__main__':
app.run(debug = True)