flask 从二进制数据返回图片 import io from flask import current_app as app from flask import send_file from myproject import Obj @app.route('/logo.png') def logo(): obj = Obj.objects.get(title='Logo') return send_file(io.BytesIO(obj.logo.read()), attachment_filename='logo.jpg', m...
fromopenpyxl.drawing.imageimportImage fromflaskimportFlask, send_file, request importbase64 importio fromioimportBytesIO fromPILimportImage as PillowImage importmath app=Flask(__name__) @app.route('/download-excel', methods=['POST']) defdownload_excel(): base64_swdt=request.form.get('base64'...
if file and allowed_file(file.filename): # 用户名作为文件名称存储 filename = secure_filename(username) + "." + file.filename.split('.')[1] # flask-config 配置 UPLOAD_DIR存放地址 file.save(os.path.join(current_app.config.get("UPLOAD_DIR"), 'avatar', filename)) return True return...
app=Flask(__name__)@app.route('/generate_image')defgenerate_image():img=Image.new('RGB',(100,100),color='red')img_io=io.BytesIO()img.save(img_io,'PNG')img_io.seek(0)returnsend_file(img_io,mimetype='image/png',as_attachment=True,download_name='generated_image.png')if__name_...
fromPILimportImageimportqrcodefromioimportBytesIOfromflaskimportFlask,send_file,jsonify,requestimportsysimportbase64importrandom app=Flask(__name__)#二维码创建路由1@app.route("/api/QRcode/create/",methods=["GET","POST"])defcode_share():ifrequest.method=='GET':url64=request.args.get("url")...
# app.pyfromflaskimportsend_fileimportxlsxwriter@app.route("/students/v1.0/excel", methods=["GET"])defstudents_excel():"""1. 生成表头 2. 生成数据 3. 个性化合并单元格,修改字体属性、修改列宽 3. 返回给前端"""fp = io.BytesIO()# 生成一个BytesIO对象book = xlsxwriter.Workbook(fp)# 可以...
from io import BytesIO as BiOimport randomfrom flask import send_filefrom io import BytesIOfrom PIL import Image as Imgfrom numpy import arrayimport cv2from PIL import ImageTkimport osfrom flask import render_template as renderimport math as mathfrom matplotlib import pyplot as pltfrom matplotlib...
创建一个简单的Flask应用并展示Matplotlib图表: from flask import Flask, send_file import matplotlib.pyplot as plt import io app = Flask(__name__) @app.route('/') def plot(): img = io.BytesIO() plt.plot([1, 2, 3, 4], [10, 20, 25, 30]) ...
(), filename) # Figure out how flask returns static files # Tried: # - render_template # - send_file # This should not be so non-obvious return open(src).read() except IOError as exc: return str(exc) @app.route('/', methods=['GET']) def metrics(): # pragma: no cover ...
import io app = Flask(__name__) @app.route('/remove-bg', methods=['POST']) def remove_bg(): file = request.files['image'] input_image = Image.open(file.stream) output_image = rembg.remove(input_image) output_buffer = io.BytesIO() ...