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

yipeiwu_com7年前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的新式类是2.2版本引进来的,我们可以将之前的类叫做经典类或者旧式类。 为什么要在2.2中引进new style class呢?官方给的解释是: 为了统一类(class)和类...

在Python中用has_key()方法查找键是否存在的教程

 如果给定的键在字典可用,has_key()方法返回true,否则返回false。 语法 以下是has_key()方法的语法: dict.has_key(key) 参...

selenium+python截图不成功的解决方法

selenium+python,使用webdriver的截图函数get_screenshot_as_file()截图,代码如下: from selenium import webdr...

关于pytorch中全连接神经网络搭建两种模式详解

pytorch搭建神经网络是很简单明了的,这里介绍两种自己常用的搭建模式: import torch import torch.nn as nn first: class NN...

基于python内置函数与匿名函数详解

基于python内置函数与匿名函数详解

内置函数 Built-in Functions abs() dict() help()...