【问题标题】:Flask form not getting values烧瓶形式没有得到价值
【发布时间】:2018-04-11 13:13:34
【问题描述】:
<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!"

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

【问题讨论】:

  • 所以当你打印时有错误,或者它只是打印空白?

标签: python html flask


【解决方案1】:

语法中存在问题,这就是它无法从 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 块并执行您的逻辑。

【讨论】:

    猜你喜欢
    • 2015-11-18
    • 1970-01-01
    • 2020-10-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-09-03
    • 1970-01-01
    相关资源
    最近更新 更多