How to get POSTed JSON in Flask?

前端 未结 10 1130
隐瞒了意图╮
隐瞒了意图╮ 2020-11-21 06:35

I\'m trying to build a simple API using Flask, in which I now want to read some POSTed JSON. I do the POST with the Postman Chrome extension, and the JSON I POST is simply <

10条回答
  •  盖世英雄少女心
    2020-11-21 07:03

    The following codes can be used:

    @app.route('/api/add_message/', methods=['GET', 'POST'])
    def add_message(uuid):
      content = request.json['text']
      print content
      return uuid
    

    Here is a screenshot of me getting the json data:

    You can see that what is returned is a dictionary type of data.

提交回复
热议问题