如何将url中的变量传递给python flask

时间:2017-10-27 06:50:58

标签: javascript python angularjs flask

我正在使用angularjs将数据传递到后端(python flask)

var currenttopic = "All";
    $http.post("/CA/"currenttopic,date).success(function(response){
                console.log(response);
            });

在后端,python烧瓶代码类似于

@app.route('/CA/<topic>', methods=['POST'])
@login_required
def competitivepertopic(topic):
    if request.method == 'POST':
        print(topic)
        data = request.get_json()
        pass
    return json.dumps({'data': topic})

现在我如何将currenttopic变量传递给后端?

1 个答案:

答案 0 :(得分:2)

试试这样:

$http.post("/CA/" + currenttopic, date).success(function(response) {

或与ES6:

$http.post(`/CA/${currenttopic}`, date).success(function(response) {