javascript - 如何将url中的变量传递给pythonflask

标签 javascript python angularjs flask

我正在使用 AngularJS 将数据传递到后端(Python Flask)

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

在后端,Python Flask 代码类似于

@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})

现在我如何将当前主题变量传递到后端?

最佳答案

尝试这样:

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

或者使用 ES6:

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

关于javascript - 如何将url中的变量传递给pythonflask,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46969118/

相关文章:

javascript - ngIf 始终评估为 true

javascript - 访问 ng-repeat 中的特定 Controller

python - 带掩码的 numpy 赋值

python - 如何确定 DAG 在 Airflow 中是否暂停/未暂停?

python - '角色'对象没有属性 '__name__'

asp.net-mvc - Angular 与 .NET Web API 验证和单点真实性

javascript - 显示数组中的随机内容

javascript - 如何在 SQL 中保存 OFFSET 的当前状态

php - 将动态生成的列表中的数据从一个页面传递到另一个页面

angularjs - Angular ui-router 的 ui-sref 在指令中动态创建?