1

Model.save() in backbone.js sends the model data as POST to server as a JSON encoded string. Its just a string and not variable=jsonString as in a normal POST request. So I cant access it in Flask as request.form.get('variable'). Where should i be editing code? Can Flask deal such requests? Can Backbone.js send data like a normal post request and not as a JSON encoded string?

Can provide more info if required.

Jaseem
  • 2,236
  • 6
  • 28
  • 35

1 Answers1

6

With Backbone the request Content-Type header is automatically set to 'application/json' (unless you've enabled emulateJSON), so Flask should automatically parse the JSON and make it available through the request object.

@app.route('/some_route', methods=['POST', 'GET'])
def some_route():
    if request.method == 'POST':
        """ json available through request.json """

http://flask.pocoo.org/docs/api/#flask.Request.json

hlindset
  • 440
  • 2
  • 7
  • Can I access it like `request.json['username']` or `request.json.username` or do i need to parse json in some other way ? – Jaseem Apr 16 '12 at 22:25