2017-02-14 2 views
0

フォームlogin.htmlです:フォームでの入力のnameパラメータはそれのために任意のHTMLフォームで必要とされるフラスコ形ポストコール - のRequest.Formは空のdict

@app.route("/", methods=["GET", "POST"]) 
def login(): 
    if request.method == "POST": 
     print(request.form) # prints empty dict 
    return render_template("login.html") 

答えて

1

<form method="POST"> 
    <input type="text" placeholder="username" required> 
    <input type="password" placeholder="password" required> 
    <button type="submit">Sign in</button> 
</form> 

app.pyPOSTになります。それ以外の場合は処理されません。

だから、右のHTMLはlogin.html次のようになります。

<form method="POST"> 
    <input type="text" placeholder="username" name="username" required> 
    <input type="password" placeholder="password" name="password" required> 
    <button type="submit">Sign in</button> 
</form> 

フラスコは名前と値によって、入力要素までdictにできるはずです。

関連する問題