【发布时间】:2019-05-09 20:03:44
【问题描述】:
我是编程新手,需要您的帮助 -
在我的 python/flask routes.py 脚本中,我有几个 app.routes。我想将路由的名称传递给 html 表单操作字段,以便将表单中的值发布到该名称的路由;
@app.route('/interfaceStats', methods=['GET', 'POST'])
def interfaceStats():
routeName='interfaceStats'
hostname = request.form['hostname']
username = request.form['username']
password = request.form['password']
command = ['python', 'readOperData.py', hostname, username,password]
print(command)
subIntObject = subprocess.check_output(command, shell=False)
intObjectInString = subIntObject.decode('ascii')
interfaceObjInJsonify = jsonify(intObjectInString)
interfaceObjInJson = json.loads(intObjectInString)
return render_template('interfaceStats.html', interfaceObjInJson=interfaceObjInJson, hostname=hostname)
<form id="submit-form" action={{routeName}} method="POST">
Hostname:
<input type="text", name="hostname" required>
Username:
<input type="text" name="username" required>
Password:
<input type="password" name="password" required>
<br>
<input type="submit" id="submit-form" class="hidden" />
</form>
错误:
在服务器上找不到请求的 URL。如果您输入了 URL 请手动检查您的拼写,然后重试。
192.168.254.1 - - [09/May/2019 15:49:56] "GET /method=%22POST%22?hostname=192.168.253.144&username=admin&password=password HTTP/1.1" 404 -
【问题讨论】: