【发布时间】:2018-04-03 10:53:38
【问题描述】:
这个问题可能是重复的,但我已经检查了此类相关问题的所有答案,但我无法解决。
我正在尝试从包含数字的下拉菜单中获取值。然后我想将数字与一个值进行比较,并根据比较显示一个文本。
例如
if value_selected_from_dropdown >3
display text
我无法让文本显示甚至打印所选选项的值。
这里是python文件,web_plants.py
from flask import Flask, render_template,request, redirect, url_for
app = Flask(__name__)
def template(title = "HELLO!", text = ""):
templateDate = {
'text' : text
}
return templateDate
@app.route("/threshold", methods=['POST'])
def threshold():
tvalue= (request.form.get['tvalue']) #get value from dropdown
msg= ""
if tvalue>3:
msg= "rating above 3"
templateData = template(text = msg) #display text using template()
#templateData = template(text = tvalue) #tried to print the value selected
return render_template('index.html', **templateData)
if __name__ == "__main__":
app.run(host='0.0.0.0', port=80, debug=True)
index.html:
<!DOCTYPE HTML>
<html>
<head>
<link rel="stylesheet" type="text/css" href="{{ url_for('static',filename='style.css')}}" />
</head>
<body>
<h2> {{ text }} </h2>
<form action= "{{ url_for('threshold') }}" method="post>"
<p>
<select name= 'tvalue'>
<option value="10">10</option>
<option value="11">11</option>
<option value="15">15</option>
<option value="2">2</option>
<option value="1">1</option>
</select>
</p>
</form>
</body>
</html>
【问题讨论】:
-
method="post>"是一个错字。应该是method="post"> -
@noslenkwah 感谢您指出这一点。