Return JSON response from Flask view

前端 未结 15 2582
时光取名叫无心
时光取名叫无心 2020-11-21 05:11

I have a function that analyzes a CSV file with Pandas and produces a dict with summary information. I want to return the results as a response from a Flask view. How do I r

15条回答
  •  暗喜
    暗喜 (楼主)
    2020-11-21 05:45

    As of version 1.1.0 Flask, if a view returns a dict it will be turned into a JSON response.

    @app.route("/users", methods=['GET'])
    def get_user():
        return {
            "user": "John Doe",
        }
    

提交回复
热议问题