這個問題在這里已經有了答案: 如何在 Flask 中提供靜態檔案 (24 個回答) 2 天前關閉。
我有兩個 API,一個基本上用于根據發送的資料生成 PDF。
下面的第一個 API 端點
http://localhost:5000/api/sendReceiptData
以附件形式回傳 PDF 檔案。
第二個 API 將使用第一個 API,并應在回應中回傳 PDF 作為附件。我已經試過了,但我收到這個錯誤TypeError: Object of type bytes is not JSON serializable
因此,我如何從第二個 API 中的第一個 API 回傳檔案回應
uj5u.com熱心網友回復:
您需要使用send_file方法回傳pdf檔案
from flask import Flask, make_response, send_file
app = Flask(__name__)
@app.route("/pdf/<string:filename>")
def return_pdf(filename):
return send_file(filename)
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/403769.html
標籤:
