我是编程的新手,需要您的帮助-
在我的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--[2019年5月9日15:49:56]“ GET /method=%22POST%22?hostname=192.168.253.144&username=admin&password=password HTTP / 1.1“ 404-
答案 0 :(得分:0)
您需要在action属性周围加上引号。
<form id="submit-form" action="{{routeName}}" method="POST">