post方法烧瓶和angularJS

时间:2014-09-15 23:40:15

标签: python angularjs flask

我是使用烧瓶的新手。我一直试图做一个函数来处理一个post请求,问题是:在角度控制器中它总是出错或者如果它不是一个错误我无法访问在相应的python函数中发送的数据。

这就是我所拥有的:

AngularJS控制器:

$http({
        method  : 'POST',
        url     : 'http://localhost:5000/holapost',
        headers: { 'Content-Type': 'application/json' },
        data: JSON.stringify({sent: $scope.TextToSend)
    })
      .success(function(data) {
           irrelevant....
        })
      .error(function(data) {
            irrelevant....
        });
  };

python flask

def post_1():
  received=request.data
  .....
  return jsonify({'msj': "what was sent was received well"})

有什么不对吗?感谢任何帮助,谢谢!

1 个答案:

答案 0 :(得分:0)

我对AngularJS没有多少经验,但在查看https://docs.angularjs.org/api/ng/service/ $ http的文档后,你的http调用看起来很好。

对于Flask,请确保您通过post_1()路由@app.route('/holapost')。关于无法访问帖子请求中的数据,该文档建议使用form属性:request.form。 (http://flask.pocoo.org/docs/0.10/quickstart/#the-request-object

如果您使用调试器运行烧瓶应用程序,使用:app.run(debug=True)也会有所帮助。我希望这有帮助!

相关问题