Hello,
i have a sample web appliaction which get a value from HTML text feild and redirect to HTML page according to the value passed
but the problem is that i can't get the value entered in the html text throught (request.form) method
I get the below error
werkzeug.routing.BuildError: Could not build url for endpoint 'suc'. Did you forget to specify values ['name']?
from flask import Flask ,redirect, url_for, request
app = Flask (__name__)
@app.route('/suc/<name>')
def suc(name):
return "hello Boss %s" % name
@app.route('/login', methods = ['GET','POST'])
def login():
if request.method == 'post':
user = request.form['nm']
return redirect(url_for('suc',name = user))
else:
user = request.args.get('nm')
return redirect(url_for('suc',name = user))
if __name__ == '__main__' :
app.run(debug = True)
<html>
<body>
<form action = "http://localhost:5000/login" method = "post">
<p>Enter Name:</p>
<p><input type = "text" name = "nm" /></p>
<p><input type = "submit" value = "submit" /></p>
</form>
</body>
</html>
Im sure that the value of text not passed correctly to user varable becouse when i change the code and pass the value name like the following :-
return redirect(url_for('suc',name = 'hossam'))`
The code works fine