Home > Software engineering >  Retrieving Form Input using flask python Not working
Retrieving Form Input using flask python Not working

Time:11-11

@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" id="exampleFormControlInput1" placeholder="Password"></form>

This is the respective HTML code

I am a beginner programmer ...pls help me !

CodePudding user response:

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" 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')
    
  • Related