首页 > 其他 > 详细

flask 详解一

时间:2022-05-27 21:02:53      阅读:9      评论:0      收藏:0      [点我收藏+]
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

flask 详解一

原文:https://www.cnblogs.com/luweiweicode/p/15347531.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!