我通过带有数字的下拉菜单动态创建文本框,因为我选择了数字,所以创建了很多文本框,一旦我点击提交,它必须发布到烧瓶应用程序并使用文本框中的内容并打印它在我的CLI中。但我面临着难以获取文本框的内容并在Python瓶中使用它来运行其他进程。 我附上了html页面的截图。感谢您的帮助。
<!DOCTYPE html>
<html>
<head>
<body>
<label>Enter Number of Buildpacks:</label>
<select id="mySelect" onChange="onChangeDropdown()">
<option value="">Please Select....</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
</select>
<br/>
<br/>
<div id="demo">
</div>
<input type="submit" value="Submit" >
</body>
</html>
<script>
function onChangeDropdown(){
var slctdValue = parseInt(document.getElementById("mySelect").value);
document.getElementById('demo').innerHTML = buildTextboxes(slctdValue);
}
function buildTextboxes(num){
var html = "";
for (var i=0; i < num; i++){
html = html + '<br/><div><label>Buildpack Name:</label><input type="text" id="textbox"'+ i + '></div>'
}
return html;
}
</script>
&#13;
import os,re,yaml
from flask import Flask, request, render_template, redirect
port = 8080
if 'PORT' in os.environ:
port = int(os.getenv("PORT"))
app = Flask(__name__)
@app.route('/')
def index():
return render_template('TestUI.html')
@app.route('/', methods=['POST','GET'])
def submit():
if request.method == 'POST':
try:
s=request.values.get('text_1')
s1=request.values.get('text1[0]')
s2=request.values.get('text1[1]')
s3=request.values.get('text1[2]')
s4=request.values.get('text1[3]')
s5=request.values.get('text1[4]')
s6=request.values.get('text1[5]')
s7=request.values.get('text1[6]')
s8=request.values.get('text1[7]')
s9=request.values.get('text1[8]')
print(s,s1,s2,s3,s4,s5,s6,s7,s8,s9)
except Exception as ex:
print("Unexpected error:No Inputs for Buildpacks ")
return redirect(e["url"], code=302)
if __name__=="__main__":
app.run(host='0.0.0.0',port=port)
#app.run(debug=True)