How to add Content-Disposition Header in Flask?

I have a Flask code with returns my Data to a response object (in order to fetch the data from Javascript).

this is my :

@app.route('/', methods=["POST"])
def donglot(): 
    global app_url

    app_url = request.form.get("appUrl")
    appData = AppDatafromUrl(app_url)

    return jsonify(data=appData) 

How to add Content-Disposition : Attachment as header so i can put in but return as jsonify?

The jsonify shorthand won’t do it, but you can use this instead:

	return Response(json.dumps(appData), mimetype="application/json",
		headers={"Content-disposition": "attachment"})
1 Like

it works! thanks @Rosuav

1 Like

Awesome :slight_smile: Have fun with it!