2016-03-07 132 views
-1

我是新來的燒瓶,如此裸露與我。從JavaScript傳遞參數到燒瓶蟒蛇腳本

目前我有一個使用$ http.get來調用我的python燒瓶腳本的angularjs文件。

在這個燒瓶腳本中,我想調用另一個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() 

任何幫助,將不勝感激!

回答

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 
+1

你好,謝謝你的回覆!我遇到問題導入請求。這是一種燒瓶方法嗎? – McCourt2364

+0

哎呀,它應該是''從瓶子進口請求''我會解決這個問題。沒有測試 –