将数据从HTML表单发送到瓶中的Python脚本下面是Python脚本中的代码:def cmd_wui(argv, path_to_tx):
"""Run a web UI."""
from flask import Flask, flash, jsonify, render_template, request import webbrowser
app = Flask(__name__)
@app.route('/tx/index/')
def index():
"""Load start page where you select your project folder
or load history projects from local DB."""
from txclib import get_version
txc_version = get_version()
prj = project.Project(path_to_tx)
# Let's create a resource list from our config file
res_list = []
prev_proj = ''
for idx, res in enumerate(prj.get_resource_list()):
hostname = prj.get_resource_host(res)
username, password = prj.getset_host_credentials(hostname)
return render_template('init.html', txc_version=txc_version, username=username)另外,我在init.html中有一个HTML表单:<form><input type="text" id="projectFilepath" size="40" placeholder="Spot your project files">
<input type="button" id="spotButton" value="Spot"></form>当用户在python脚本中的变量上单击“potButton”时,如何传递来自“projectFilepath”的用户输入?我是Python和Flask的新手,所以如果我犯了什么错误,请原谅我。
3 回答
皈依舞
TA贡献1851条经验 获得超3个赞
form
action
表单数据在提交时发送到的URL。用 url_for
..如果相同的URL处理显示表单和处理数据,则可以省略。 method
是否以查询字符串(GET)或表单数据(POST)的形式提交数据。
@app.route('/handle_data', methods=['POST'])def handle_data(): projectpath = request.form['projectFilepath'] # your code # return a response
action
<form action="{{ url_for('handle_data') }}" method="post"> <input type="text" name="projectFilepath"> <input type="submit"></form>
蝴蝶不菲
TA贡献1810条经验 获得超4个赞
from flask import request@app.route('/addRegion', methods=['POST'])def addRegion(): ... return (request.form['projectFilePath'])
<form action="{{ url_for('addRegion') }}" method="post"> Project file path: <input type="text" name="projectFilePath"><br> <input type="submit" value="Submit"></form>
添加回答
举报
0/150
提交
取消