django - Django 中的范围 slider

标签 django html python-2.7 django-templates

我的模板中有一个范围 slider 。我想在我的 View 中调用有关范围 slider 值更改的函数。

index.html
<input id="slider1" type="range" value="3" min="1" max="20" step="1" />

我正在使用按钮和文本,我还从 this 获得了帮助

Python 2.7.10 Django 1.9

最佳答案

假设您有 call_view(request)调用...

<input type="range" ... onchange="callFun(this.value)">

注意:我使用了<a href="https://developers.google.com/web/updates/2015/03/introduction-to-fetch?hl=en" rel="noreferrer noopener nofollow">fetch</a>

function callFun(value) {
    fetch('call_your_url/?value='+ value).then(function(response) {
        console.log(response.status);
    }
}

在你的 View 函数中...

def call_view(request):
    request.GET.get('value')
    return HttpResponse("success")

关于django - Django 中的范围 slider ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38719590/

相关文章:

python - setup.py 缺少 __init__.py 文件

预填充数据库的 Django 测试脚本

mysql - 不同位置的 Docker django mysql.sock

django - 无法将 get_FOO_display 与表单一起使用

php - 使用 PHP 变量的 HTML 嵌入视频不起作用

Python:多处理和请求

javascript - 如何在 Django 服务器提供的 Eclipse 中调试 javascript

jquery - 如何多次使用css transition?

javascript - 如何显示由onclick事件触发的div

python - 如果键存在,则按键对字典进行排序,如果不将其放在列表末尾