0

I have a dictionary that maps one key to multiple values and I want to send that dict as a json file for the user to download.

@app.route('/test', methods=['GET','POST'])
def test():

    data=dict()
    foods=['burger','hotdog']
    foods2=['fries','chips']
    data['John']=foods
    data['Ken']=foods2
    nutrition=jsonify(data)
    return Response(nutrition,
                mimetype='application/json',
                headers={'Content-Disposition':'attachment;filename=nutrition.json'})

Followed solution to a similar post, however I get an error of:

TypeError: 'Response' object is not iterable

I have also tried sending data as a parameter to Response, with no avail. Can someone explain what I'm doing wrong.

Community
  • 1
  • 1
Jaquacky
  • 561
  • 2
  • 6
  • 16

1 Answers1

3

jsonify creates a Response object for you, so you shouldn't pass that into a Response constructor.

nutrition = jsonify(data)
nutrition.headers['Content-Disposition'] = 'attachment;filename=nutrition.json'
return nutrition
ganduG
  • 615
  • 6
  • 18