Outils pour utilisateurs

Outils du site


Panneau latéral

Plan du Site:

python:flask:response_json

Renvoyer une réponse en JSON

from flask import jsonify
 
@app.route("/api/test")
def test():
    data = [
        {
            'prenom': 'robert',
            'nom'   : 'dupont',
            'age'   : 84
        }, {
            'prenom': 'albert',
            'nom'   : 'durant',
            'age'   : 78
        }
    ]
    return jsonify(data)

Ceci renvoie au navigateur une réponse de type application/json :

python/flask/response_json.txt · Dernière modification: 2021/11/07 06:48 (modification externe)