django获取from表单multiple-select的value和id的方法

yipeiwu_com6年前Python基础

如下所示:

<select id="host_list" name="host_list" multiple>
  {% for op in host_list %}
    <option id="{{ op.nid }}">{{ op.hostname }}</option>
  {% endfor %}
</select>

1、当需要获取选中的option的value时,

需设置为id="{{ op.nid }}",

django Views获取选中的值为host_value=request.POST.getlist("host_list")

获取的为选中的option的value;

2、当需要获取选中的option的id时,

需设置为value="{{ op.nid }}",

django Views获取选中的值为host_id=request.POST.getlist("host_list")

获取的为选中的option的id;

以上这篇django获取from表单multiple-select的value和id的方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持【听图阁-专注于Python设计】。

相关文章

python基于隐马尔可夫模型实现中文拼音输入

python基于隐马尔可夫模型实现中文拼音输入

在网上看到一篇关于隐马尔科夫模型的介绍,觉得简直不能再神奇,又在网上找到大神的一篇关于如何用隐马尔可夫模型实现中文拼音输入的博客,无奈大神没给可以运行的代码,只能纯手动网上找到了结巴分词...

在Python中,不用while和for循环遍历列表的实例

如下所示: a = [1, 2, 3, 8, 9] def printlist(l, index): if index == len(l): return else:...

python显示生日是星期几的方法

本文实例讲述了python显示生日是星期几的方法。分享给大家供大家参考。具体实现方法如下: # find the day of the week of a given date #...

Python数据可视化编程通过Matplotlib创建散点图代码示例

Python数据可视化编程通过Matplotlib创建散点图代码示例

Matplotlib简述: Matplotlib是一个用于创建出高质量图表的桌面绘图包(主要是2D方面)。该项目是由JohnHunter于2002年启动的,其目的是为Python构建一个...

Python创建字典的八种方式

1.创建空字典 >>> dic = {} >>> type(dic) <type 'dict'> 2.直接赋值创建 >&g...