[Flask] Flask with Json Format
Amit Jalota
amitjalota124 at gmail.com
Wed Feb 22 04:07:30 EST 2017
Hi All,
Is there is any good tutorial/handson which will return the
data in Json format with examples like handlers which will fetch the real
time data.
I went through mentioned below tutorial
https://blog.miguelgrinberg.com/post/the-flask-mega-tutorial-part-i-hello-world
and currently I hardcoded the the Json data and returned to browser
now I need to return some real time data from
microblog/virtualenv-15.1.0/app/views.py
instead of hardcoded.
from flask import Flask,jsonify,json
from app import app
@app.route("/getEmployeeList")
def getEmployeeList():
try:
# Initialize a employee list
employeeList = []
# create a instances for filling up employee list
for i in range(0,2):
empDict = {
'firstName': 'Roy',
'lastName': 'Augustine'}
employeeList.append(empDict)
# convert to json data
jsonStr = json.dumps(employeeList)
except Exception ,e:
print str(e)
return jsonify(Employees=jsonStr)
and can you please help me for interface as well to lower backed layer.
Thanks
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/flask/attachments/20170222/67c7a188/attachment.html>
More information about the Flask
mailing list