2017-08-19 11 views
0

私はボトルに、POST経由でHTMLからのユーザー入力を読み込む小さなスクリプトを書いています。 HTMLのスクリプトで解析できるボトル関数から結果をHTMLに戻したいと思います。ボトルから返されたメッセージを処理するためのHTMLのスクリプト

ボトルコード:これまで

@app.route("/") 
def index(): 
    return template("user_info.tpl", message = "please enter your data: ") 
@app.route("/", method="POST") 
def formhandler(): 

    x = int(request.forms.get('x')) 
    y = int(request.forms.get('y')) 
    piece = request.forms.get("value") 
    final_output = int(slope)*int(value) + int(intercept) 
    return template("user_info.tpl", message=str(final_output)) 
app.run(host="localhost", port = 8080, debug = True) 

マイHTML:私のHTMLファイルのボトルで

<html> 
<head> 
<title>Form Example</title> 

</head> 
<body> 
    <form method="post" action="/"> 
    <fieldset> 
    <legend>SAMPLE FORM</legend> 
    <ul> 
     <li>Enter the row: <input name='x'> 
     </li> 
     <li>Enter the column: <input name='y'> 
     </li> 
     <li>Enter the piece name: <input name ="name"> 
     </li> 
    </ul><input type='submit' value='Submit Form'> 
    </fieldset> 
</form> 

<p>Quantitity: {{message}}</p> 

<script type="text/javascript"> 
if (message >= 100) 
{ 
    window.alert("Too high"); 
} 
else { 

    window.alert("Just perfect"); 
} 

</script> 

、私は分析するのに非常に簡単なスクリプトを実行しようとしています戻り値ただし、コントロール条件に一致する値を入力しても、ポップアップはトリガーされません。これをどうやって解決するのですか?

+1

このような条件の場合はjavascriptを指定する必要があります'if({{message}}> = 100)'それだけで変数を取得します。コンソールに行って、存在する値をスクリプトで確認することができます。 –

答えて

1

私はいくつかの可能性のある問題を参照してください。

  1. request.forms.get("value") - フォーム
  2. final_output = int(slope)*int(value) + int(intercept)に値フィールドがありません - NO「あなたはドンコード
  3. slopeinterceptの言及tにmessageのJSがあるので、var message = {{message}}をセクションに追加してください。
+0

ありがとうございました!あなたは正確な欠陥を指摘しました。それは今働く。 – Ajax1234

+0

@ Ajax1234、ようこそ) –

関連する問題