2

I'm sending data via AngularJS POST request:

$http.post('/process', { 'uid': uid, 'action': action }).success(function(response) {
    console.log(response);
});

And trying to get sended values in Flask

@app.route('/process', methods = ['POST'])
def process():
    return json.dumps({ 'data': request.form.get('uid', 'EMPTY') })

And Flask returns back {"data": "EMPTY"} response. request.form is empty. I've tried to get data from request.data, but it's in strange format there.

I'm learning Python and Flask so I want to do this work with native library, without any other packages right now.

2
  • why you aren't using request.args? Commented Nov 30, 2014 at 12:40
  • @taskiner cause they are for GET requests Commented Nov 30, 2014 at 13:29

3 Answers 3

5

get_json() method helps me

@app.route('/process', methods = ['POST'])
def process():
    return json.dumps({ 'data': request.get_json().get('uid') })
Sign up to request clarification or add additional context in comments.

Comments

0

If you want to get the data via request.form, you need to have angular send it differently. See this question for details: How can I post data as form data instead of a request payload?

Comments

0

Make sure Content-Type is application/json

Here's a tutorial series on using Flask and AngularJS together - http://tutsbucket.com/tutorials/building-a-blog-using-flask-and-angularjs-part-1/

Hope you'll find it useful.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.