【问题标题】:flask type error, list object not callable烧瓶类型错误,列表对象不可调用
【发布时间】:2017-11-21 04:22:42
【问题描述】:

我正在使用 Jquery 中的 Ajax 发布请求将数据数组传递给烧瓶函数。但是烧瓶 request.form.getlist 无法获取此列表并显示类型错误:列表对象不可调用

我的代码:

@app.route('/DeleteRow', methods=['POST'])
def signUpUser():
    if request.method == "POST":
        clicked=request.form.getlist('id[]')
    print(clicked[0])

ids 是发送到 Ajax 发布请求的数组:

var ids = new Array();
  for(i=0;i<table.rows('.selected').data().length;i++)
  {
      ids[i]=table.rows('.selected').data()[i][3];
  }


  $.ajax({
   type: "POST",
   data: {id:ids},
   url: "DeleteRow",
   success: function(data){
     alert('Do you want to delete this row: ' + data);
   }
});

【问题讨论】:

    标签: python-3.x flask


    【解决方案1】:

    通过 AJAX 发出的 HTTP POST 请求的 Content-Type 标头为 application/json,因此被收集在 request.json 中。

    使用 multipart/form-data 的 Content-Type 标头发出的 HTTP 请求是在 request.form 中收集的请求。

    用途:

    clicked = request.json.get('id')
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-02-19
      • 2021-08-11
      • 2013-04-30
      • 2020-11-02
      • 2014-07-28
      • 1970-01-01
      • 2020-03-08
      相关资源
      最近更新 更多