HTML 中的脚本,用于处理 Bottle 返回的消息
Script in HTML to handle returned message from Bottle
我正在用 Bottle 编写一个小脚本,它通过 POST 从 HTML 读取用户输入。我想将结果从 HTML.
中的脚本分析的 Bottle 函数发送回 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>
<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>
在我的 HTML 文件中,我试图 运行 一个非常简单的脚本来分析返回值。但是,即使我输入了与控制条件匹配的值,也不会触发弹出窗口。我该如何解决这个问题?
我发现几个可能的问题:
request.forms.get("value")
-- 您在表单上没有值字段
final_output = int(slope)*int(value) + int(intercept)
-- 代码中没有提到 slope
和 intercept
- 你在 JS 中没有
message
变量,所以在 部分添加 var message = {{message}}
我正在用 Bottle 编写一个小脚本,它通过 POST 从 HTML 读取用户输入。我想将结果从 HTML.
中的脚本分析的 Bottle 函数发送回 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>
<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>
在我的 HTML 文件中,我试图 运行 一个非常简单的脚本来分析返回值。但是,即使我输入了与控制条件匹配的值,也不会触发弹出窗口。我该如何解决这个问题?
我发现几个可能的问题:
request.forms.get("value")
-- 您在表单上没有值字段final_output = int(slope)*int(value) + int(intercept)
-- 代码中没有提到slope
和intercept
- 你在 JS 中没有
message
变量,所以在 部分添加
var message = {{message}}