我有以下网址的代码:http://localhost/summary/myfile.csv 我希望网址看起来像这样:http:// localhost / summary?file = myfile.csv
代码应写在烧瓶中。
第一个网址的代码如下:
@app.route('/summary/<filename>',methods = ['GET'])
def api_summary(filename):
url = 'C:\\Users\\Desktop\\myproject\\'
if os.path.exists(url + filename):
data = pandas.read_csv( url + filename)
Numeric_Summary = data.describe().to_dict()
resp = jsonify(Numeric_Summary)
resp.status_code = 200
return resp
答案 0 :(得分:6)
您需要添加另一个路由并解析查询字符串:
from flask import request
@app.route('/summary',methods = ['GET'])
def api_summary_2():
filename = request.args.get('file', None)
if filename is None:
abort(404)
else:
return api_summary(filename)