如果URL调用中有双重参数,如何编写flask approute执行bash脚本?
这是我从浏览器拨打的URL
http://0.0.0.0:5000/sample/fwd
我试图这样写我的烧瓶approute。
app = Flask(__name__)
@app.route('/<port>')
def get_shell_script_output_using_check_output(port):
stdout = check_output(['./route.sh','-a',"{}".format(port)]).decode('utf-8')
return stdout
@app.route('/<port>/<fwd>')
def get_shell_script_output_using_check_output(port,fwd):
stdout = check_output(['./shadowSR.sh',"{}".format(port),"{}".format(fwd)]).decode('utf-8')
return stdout
if __name__ == '__main__':
app.run(host='0.0.0.0', port=5000)
但这不起作用。有人可以建议我如何提及approute吗?
答案 0 :(得分:0)
您可以尝试
@app.route('/run/<port>/<fwd>')
def run(port, fwd):
stdout = check_output(['./shadowSR.sh',"{}".format(port),"{}".format(fwd)]).decode('utf-8')
return stdout