Sometimes, we want to return a JSON response from a Python Flask view.
In this article, we’ll look at how to return a JSON response from a Python Flask view.
How to return a JSON response from a Python Flask view?
To return a JSON response from a Python Flask view, we an return a dictionary directly as the response.
For instance, we write
@app.route("/summary")
def summary():
d = make_summary()
return d
to get the dict d
from the make_summary
function and then return its contents as the JSON response in the /summary
view.
Conclusion
To return a JSON response from a Python Flask view, we an return a dictionary directly as the response.