python - 将滑块值传递给瓶子路线功能
问题描述
我正在尝试运行代码,但有一部分无法正常工作,我需要从滑块传递值。我可以在 html 页面中看到该值,但无法将其传递到inputRange()
需要运行某些命令的位置。
我试图只隔离与滑块一起使用的代码。您能否让我知道如何将滑块值传递给val_slide
?谢谢。
代码:
from bottle import route, run, template
IP_ADDRESS = '192.168.0.80'
PORT = 8080
@route('/')
def hello():
return '<b>Test</b>'
@route('/remote')
def remote():
return '''<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.2/jquery.mobile-1.4.2.min.css">
<script src="http://code.jquery.com/jquery-1.10.2.min.js"></script>
<script src="http://code.jquery.com/mobile/1.4.2/jquery.mobile-1.4.2.min.js"></script>
<script>
$(document).ready(function() {
$('#inputRange').on('change mouseup', function(){
var val_slide ='inputRange';
$.ajax({
url: '/remote/inputRange',
type: 'GET',
data: {command:val_slide},
});
});
});
</script>
<style></style>
</head>
<body>
<div data-role="page">
<div data-role="main" class="ui-content">
<form>
<div style="text-align:center">
<label for="switch">Test</label>
<div class="slidecontainer">
<input id="inputRange" type="range" min="0" max="100" step="1" value="20" class="slider" name='data'>
<output name="inputRange"/output>
</div>
</form>
</div>
</div>
</body>
</html>'''
@route('/remote/inputRange')
def inputRange():
print val_slide
# use val_slide value
return 'inputRange'
try:
run(host = IP_ADDRESS, port= PORT)
except(KeyboardInterrupt):
print('Done!')
quit()
解决方案
要从 GET 请求访问查询参数,您应该导入request
并使用request.query
以按名称访问值:
from bottle import route, request
@route('/remote/inputRange')
def inputRange():
val_slide = request.query.command
print(val_slide)
return val_slide
我不是 JavaScript 方面的专家,但据我所知,要发送实际值(不仅仅是静态文本),您需要val_slide
用读取值替换静态文本赋值:
var val_slide = this.value;
推荐阅读
- c - Linux内核模块:我的变量在线程函数中使用时丢失了它的值
- python - Pandas 数据框应用函数返回新列会导致标量错误?
- azure - 错误:为机器学习服务 Workpsace 部署 Azure ARM 模板时,“确保使用支持 MSI 的客户端创建工作区”
- javascript - 使用 CropperJS 旋转合适的画布
- ubuntu - 什么是 headless_lib.pak?是否应该将无头库复制到 AArch64 设备?
- javascript - 如何解决 jquery 子方法警报错误?
- python - 运行本地 mlflow 服务器时出错
- python - 基本 Python - SyntaxError:解析时意外 EOF - if 语句
- unix - 为 IBM AIX 显示每个文件系统驻留在哪些 hdisk 上的脚本
- javascript - 动态注释掉 CSS 样式表?