используйте сообщение AJAX.
let myVar = 'Hello'
$.post('http://localhost:5000/getjs', {myVar}, function(){
// Do something once posted.
})
и ваша колба будет выглядеть примерно так
@app.route('/getjs', methods=['POST'])
def get_js():
if request.method == 'post':
js_variable = request.form
return js_variable
В качестве альтернативы вы можете сделать это:
@app.route('/getjs/<variable>')
def get_js(variable):
js_variable = variable
return js_variable
таккогда вы направите свой URL-адрес на http://localhost:5000/getjs/apples js_variable будет «яблоки»