33 lines
748 B
Python
33 lines
748 B
Python
from flask import send_file
|
|
|
|
|
|
def send_excel(file_handler, file_name, suffix='xlsx'):
|
|
"""
|
|
发送 excel 文件
|
|
:param file_handler:
|
|
:param file_name:
|
|
:param suffix:
|
|
:return:
|
|
"""
|
|
return send_file(
|
|
file_handler,
|
|
mimetype='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
|
|
attachment_filename='{}.{}'.format(file_name, suffix),
|
|
as_attachment=True
|
|
)
|
|
|
|
|
|
def send_png(img_handler, name='image'):
|
|
"""
|
|
发送图片文件(可用于验证码)
|
|
:param img_handler:
|
|
:param name:
|
|
:return:
|
|
"""
|
|
return send_file(
|
|
img_handler,
|
|
mimetype='image/png',
|
|
attachment_filename='{}.png'.format(name),
|
|
as_attachment=True
|
|
)
|