【问题标题】:sending the value of HTML checkbox to django view将 HTML 复选框的值发送到 django 视图
【发布时间】:2016-10-04 15:49:49
【问题描述】:

我有以下 HTML 页面

<input type="checkbox" name="checks[]" value="1">REG_AGREED_SUITE01
  </label>
   <hr>
  <label class="checkbox">
  <input type="checkbox" name="checks[]" value="2">REG_AGREED_SUITE02
  </label>
   <hr>
  <label class="checkbox">
  <input type="checkbox" name="checks[]" value="3">REG_AGREED_SUITE03
  </label>

我有一个这样的 Django 视图

cd1 = "<command>"
cd2 = "</command>"
test_runner_path = "Abc - C:\git_new\evo_automation\ tests\TestRunner"
test_runner_path2 = "Def - C:\git_new\evo_automation\ tests\TestRunner"
STB = "VMS_01"
TestSuite = "REG_AGREED_SUITE02"

现在我正在从视图中手动传递 TestSuite 值。但我想,如果我从 html 页面中选择复选框,它应该替换视图中的硬编码值并传递参数。有什么办法可以吗?

【问题讨论】:

  • 当您点击表单中的按钮Submit 时,视图将获得带有表单值的requestrequest.POST
  • 谢谢你 furas.. 现在我没有任何表格。我只是想通过在 html 中选择的任何复选框应该进入“TestSuite”中的该视图。我发现这种方式 TestSuite = request.POST.getlist('checks[]')。但这对我不起作用。

标签: python html django jenkins


【解决方案1】:

使用jquery和ajax请求传递数据查看:

   $("checkbox").change(function(){
        $.post("path/to/url",
        {
            checkBoxValue: $("#CheckboxID").val()
        }
    });

【讨论】:

  • 可能 OP 还没有button。也许显示当复选框更改值时如何执行功能。
猜你喜欢
  • 1970-01-01
  • 2019-09-18
  • 2021-12-24
  • 2021-10-25
  • 2011-05-26
  • 2022-08-20
  • 2015-05-18
  • 1970-01-01
  • 2017-12-07
相关资源
最近更新 更多