烧瓶形式没有获得价值

时间:2018-04-11 13:13:34

标签: python html flask

<form action="/signup" method="post">
    <input type="email" name="InputEmail" id="InputEmail" class="form-control input-sm chat-input" placeholder="Email"/>
    </br>
    <input type="text" name="InputPassword" id="InputPassword" class="form-control input-sm chat-input"
           placeholder="Password"/>
    </br>
    <input type="text" name="InputConfirmPassword" id="InputConfirmPassword" class="form-control input-sm chat-input"
           placeholder="Confirm Password"/>
    </br>
    <div class="wrapper">
        <span class="group-btn">  
            <button type="submit" class="btn btn-danger">SignUp</button>   
        </span>
    </div>
</form>

这是我的html代码,其中包含我要提取数据的from标记,但我没有在Python中获取电子邮件,密码和确认密码字段! 这是我的python代码!

@app.route("/signup",methods=['GET','POST'])
def signup():
    email = request.form.get('InputEmail')
    password = request.form.get('InputPassword')
    confirm_password = request.form.get('InputConfirmPassword')
    print str(email)
    print str(password)
    print str(confirm_password)
    return "You have signed up!"

所有这些印刷声明都没有给我。有什么帮助解决这个问题吗?

1 个答案:

答案 0 :(得分:0)

语法中存在一个问题,即它无法从HTML表单中获取值。尝试使用下面提到的代码。

@app.route("/signup",methods=['GET','POST'])
def signup():
    if request.method == "POST":
        email = request.form['InputEmail']
        password = request.form['InputPassword']
        confirm_password = request.form['InputConfirmPassword']
        print str(email)
        print str(password)
        print str(confirm_password)
        return "You have signed up!"
    return render_template("html_file.html")

在上面的代码中,它将首先呈现模板“html_file.html”。当我们提交表单时,它将生成一个POST请求。之后它将进入if块,你的逻辑将被执行。