簡體   English   中英

如何與燒瓶響應對象一起發送數據?

[英]How can I send data together with flask response object?

這是我發送數據的代碼:

@app.route('/testColoring')
def testColoring():
     ...
     return jsonify({'image_url': imgPath})

但是,我想將其作為Response對象發送,因為我想設置標題以禁用緩存。 像這樣:

response = make_response()
response.headers['Cache-Control'] = 'no-cache, no-store, must-revalidate'
response.headers['Pragma'] = 'no-cache'

起初,我以為是response.data,但是根據flask API文檔 ,不應使用它,並且將不建議使用。

請建議我如何結合響應和json數據,或其他可能的解決方案。 謝謝。

jsonify返回一個響應對象。 與其直接返回,不如設置一個變量並在返回之前修改標題。

rv = jsonify(data)
rv.headers.set('Cache-Control', 'no-cache, no-store, must-revalidate')
return rv

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM