from flask import Flask, render_template, request, redirect, url_for, json, Response import requests from werkzeug.utils import secure_filename import os import redis from flask_cors import CORS app = Flask(__name__) @app.route(‘/findAllPics‘) def hello_world(): r = redis.StrictRedis(host=‘172.16.37.50‘, port=6379, db=2, decode_responses=True) smembers = r.smembers("img_list") s = list(smembers) print(s) t = {} t[‘c‘] = s return Response(json.dumps(t), mimetype=‘application/json‘) @app.route(‘/upload‘, methods=[‘POST‘, ‘GET‘]) def upload(): if request.method == ‘POST‘: f = request.files[‘file‘] basepath = os.path.dirname(__file__) # 当前文件所在路径 upload_path = os.path.join(basepath, r‘file\uploads‘, secure_filename(f.filename)) # 注意:没有的文件夹一定要先创建,不然会提示没有该路径 f.save(upload_path) url_dis = "http://172.18.102.168:8080/zx_ocr_bl" files = {‘image_file‘: open(upload_path, ‘rb‘)} res = requests.post(url=url_dis, files=files) t = {} t[‘c‘] = str(res.text) dumps = json.dumps(t, sort_keys=True, indent=2) print(dumps) return Response(dumps, mimetype=‘application/json‘) if __name__ == ‘__main__‘: CORS(app, supports_credentials=True) app.run(debug=True, host=‘0.0.0.0‘, port=5000)
https://dormousehole.readthedocs.io/en/latest/quickstart.html#id2
原文:https://www.cnblogs.com/luweiweicode/p/15347531.html