将参数从Javascript传递给flask python脚本

时间:2016-03-07 20:43:16

标签: javascript python angularjs flask

目前我有一个angularjs文件,它使用$ http.get来调用我的python flask脚本。

在这个烧瓶脚本中,我想再调用另一个python脚本(运行pySolr),但http.get调用包含一个我希望传递给这个pySolr脚本的参数。

是否有关于此的文件/它是否可以实际完成?

$http.get('http://localhost:5000/python/solr', "$scope.tag");
console.log($scope.tag);

$ scope.tag是我需要的变量

我的烧瓶文件如下:

from flask import Flask
app = Flask(__name__)

@app.route('/python/solr')
def solr():
    "MY CODE TO CALL SOLR SCRIPT GOES HERE"


if __name__ == "__main__":
app.run()

1 个答案:

答案 0 :(得分:2)

您应该可以使用查询参数执行此操作:

$http.get('http://localhost:5000/python/solr?tag=' + $scope.tag);
console.log($scope.tag);

在烧瓶中

from flask import request

@app.route('/python/solr')
def solr():
    print request.args  # should get tag here