How to return multiple json file in same route flask?
By using Axios, I can successfully fetch one JSON file returned from flask. Now I have another JSON file that needs to be pass to the same route: /dashboard, is it possible to return several JSON files in one route?
ps. I'm a newbie in flask
Below are the codes:
@app.route("/dashboard", methods= ['GET'])
def key_index():
try:
key_index = db.sns.find({},{"_id":0}).sort([("datetime", -1)]).limit(1)
return dumps(key_index)
except Exception as e:
return dumps({'error': str(e)})
@app.route("/dashboard", methods= ['GET'])
def sns_trend():
try:
trend = db.sns_2.find({})
return dumps(trend)
except Exception as e:
return dumps({'error': str(e)})
#1 Answers
a single letter json you can return 2 data example
@app.route("/dashboard", methods= ['GET'])
def key_index():
try:
key_index = db.sns.find({},{"_id":0}).sort([("datetime", -1)]).limit(1)
trend = db.sns_2.find({})
return dumps({
'key_index':key_index,
'trend':trend
})
except Exception as e:
return dumps({'error': str(e)})
Comments
Post a Comment