flask⽹页pdf⽂件预览
# -*- coding:utf8 -*-
import flask
from flask import send_file, make_response
app = flask.Flask(__name__)
@ute('/pdf/<report_id>', methods=['GET'])
def post(report_id):
headers =("Content-Disposition",f"inline;filename={report_id}.pdf")#⽂件预览
as_attachment =False
# headers = (f"Content-Disposition", f"attachement;filename={report_id}.pdf")#⽂件下载
网页app
# as_attachment = True
file_path ='/home/xxxxxxx/pdf/{}.pdf'.format(str(report_id))
response = make_response(send_file(filename_or_fp=file_path, as_attachment=as_attachment))    response.headers[headers[0]]= headers[1]
return response
if __name__ =='__main__':
app.run(host='0.0.0.0', port=9003)

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。