Flask Python, trying to return list or dict to Ajax call

后端 未结 3 1840
不知归路
不知归路 2021-02-05 04:21

Within a Flask app, I have the following ajax call:

    $.ajax({
            url: \"{{ url_for( \'bookings.get_customer\' ) }}\",
            type: \"POST\",
            


        
3条回答
  •  梦谈多话
    2021-02-05 04:38

    josonify works..but if you intend to just pass an array without the 'results' key, you can use json library from python. The following conversion works for me..

     import json
    
     @app.route('/test/json')
     def test_json():
     list = [
            {'a': 1, 'b': 2},
            {'a': 5, 'b': 10}
           ]
     return json.dumps(list)
    

提交回复
热议问题