Ошибка «плохого запроса» на колбе [дубликат]

Простое решение с ES5 (перезаписать существующее значение):

function merge(current, update) {
  Object.keys(update).forEach(function(key) {
    // if update[key] exist, and it's not a string or array,
    // we go in one level deeper
    if (current.hasOwnProperty(key) 
        && typeof current[key] === 'object'
        && !(current[key] instanceof Array)) {
      merge(current[key], update[key]);

    // if update[key] doesn't exist in current, or it's a string
    // or array, then assign/overwrite current[key] to update[key]
    } else {
      current[key] = update[key];
    }
  });
  return current;
}

var x = { a: { a: 1 } }
var y = { a: { b: 1 } }

console.log(merge(x, y));

1
задан Bonbin 12 October 2016 в 10:17
поделиться

1 ответ

Из кода JS вызовите (используя метод GET) URL-адрес вашего флеш-маршрута, передав параметры в качестве запросов args:

/list?freesearch=value1&limit_content=value2

Затем в определении вашей функции:

@app.route('/list')
def alist():
    freesearch = request.args.get('freesearch')
    limitcontent = request.args.get('limit_content')
    new = freesearch + limitcontent
    return render_template('list.html', title="Projects - "+page_name, new=new)

В качестве альтернативы вы можете использовать переменные пути:

/list/value1/value2

и

@app.route('/list/<freesearch>/<limit_content>')
def alist():
    new = free_search + limit_content
    return render_template('list.html', title="Projects - "+page_name, new=new)
1
ответ дан Jérôme 19 August 2018 в 06:18
поделиться
  • 1
    Спасибо! Как добавить /list?freesearch=value1,limit_content=value2 в свой javascript? – Bonbin 12 October 2016 в 10:36
  • 2
    AFAIU, то, что вы хотите сделать, - это выполнить GET (или POST, это зависит от вас) от вашего JS-кода до вашего приложения python flask. О том, как выполнить запрос от JS, см. этот ответ . – Jérôme 12 October 2016 в 10:38
Другие вопросы по тегам:

Похожие вопросы: