0

This is my code for sending data:

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

However, I would like to send it as a Response object, because I want to set the headers to disable cache. Something like this:

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

At first, I thought it would be response.data, but according to the flask API documentation it should not be used and it will be deprecated.

Please advise on how I could combine response and json data, or other possible solutions. Thanks.

matchifang
  • 5,190
  • 12
  • 47
  • 76

1 Answers1

1

jsonify returns a response object. Instead of returning it directly, set a variable and modify the headers before returning.

rv = jsonify(data)
rv.headers.set('Cache-Control', 'no-cache, no-store, must-revalidate')
return rv
davidism
  • 121,510
  • 29
  • 395
  • 339