-1
@app.route('/signup',methods=["GET","POST"])
def signup():
    return render_template('signup.htm')
    password = request.form['password']
    if password =="python":
        return redirect(url_for("home"))

This is my python code for retrieving form input and then to redirect the user to the home page if the password is "python".

<form action="#" method="POST" name="password">
<input type="password" class="form-control" 
       id="exampleFormControlInput1" placeholder="Password">
</form>

This is the respective HTML code for the signup page.

Anand Sowmithiran
  • 2,591
  • 2
  • 10
  • 22
  • 1
    You are returning unconditionally on the first line. The line `password =` will never be executed. – mcsoini Nov 11 '21 at 06:55
  • Check out the examples in the docs https://flask.palletsprojects.com/en/2.0.x/patterns/wtforms/ – mcsoini Nov 11 '21 at 06:57
  • 1
    Also, the HTML in your signup.htm, the password field ID must be set properly, to the same value you read from request object. You have named it as exampleFormControlInput1 , it will not match request.form['password'] – Anand Sowmithiran Nov 11 '21 at 06:58

1 Answers1

0

you are using name="password" in your form attributes which is wrong. You have to use it in attributes of input So HTML should be like this

<form action="#" method="POST"><input type="password" name="password" class="form-control" id="exampleFormControlInput1" placeholder="Password"></form>

Also in python you are returning first which is also wrong return is last statement of function

So python code must be like this

@app.route('/signup',methods=["GET","POST"])
def signup():
    if(requset.method == 'POST'):
        password = request.form['password']
        if password =="python":
            return redirect(url_for("home"))
    else:
        return render_template('signup.htm')