【问题标题】:how to pass variable in url to python flask [duplicate]如何将url中的变量传递给python烧瓶[重复]
【发布时间】:2018-04-08 17:01:50
【问题描述】:

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

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 变量传递给后端?

【问题讨论】:

  • 这是一个不同的问题

标签: javascript python angularjs flask


【解决方案1】:

试试这样:

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

或使用 ES6:

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

【讨论】:

  • 那是波浪号吗?
  • 第一行对我有用。感谢您的帮助
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-08-20
  • 1970-01-01
  • 2020-12-21
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多