简体   繁体   中英

Python - Flask - Request.form not working

I'm working with the Flask framework for Python, and I am trying to use backbone.js as a frontend, at the end of the function, I do

return jsonify(results=data)

to return a json result. The issue here, however, is that backbone cannot accept the results namespace, and I cannot find a way to go without it. Ideas?

Thanks in advance

If this is a model you should be returning your model attributes. If it is a collection you should be returning a list of the attributes of the collection's models .

Now if you have a look at what jsonify actually does, you will find out that it constructs a dict with whatever args and kwargs you pass it and calls json.dumps (or simplejson.dumps for older pythons).

So if you return a model

return jsonify({'id': 'foo', 'title' :'Foo'})

or even

return jsonify(id='foo', title='Foo')

For a collection

return jsonify([{'id': 'foo', 'title': 'Foo'}, {'id': 'bar', 'title': 'Bar'}])

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM