Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html 使用属性role=";菜单“;在Django表单的下拉菜单中_Html_Django_Twitter Bootstrap 3 - Fatal编程技术网

Html 使用属性role=";菜单“;在Django表单的下拉菜单中

Html 使用属性role=";菜单“;在Django表单的下拉菜单中,html,django,twitter-bootstrap-3,Html,Django,Twitter Bootstrap 3,我正在用Django制作一个注册页面,这是其中的一部分: <div class="dropdown"> <button id="dLabel" class="form-control form-white dropdown" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> Catégorie </button>

我正在用
Django
制作一个注册页面,这是其中的一部分:

<div class="dropdown">
  <button id="dLabel" class="form-control form-white dropdown" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
          Catégorie
  </button>                             
        <ul role="menu" aria-labelledby="dLabel" name="spec">
    {%for cat in spec%}
      <li value={{cat.id}}><a href="#">{{cat.categorie}}</a></li>
    {% endfor %}
        </ul>                                       
</div>

凯蒂戈里酒店
    {spec%中的cat为%1} {%endfor%}
问题是,这不是填充表单中
spec
字段的有效方法,因此无论我选择什么选项,它都始终为NULL。那么我该如何解决这个问题。

您需要使用而不是下拉列表。下拉列表不是为从列表中选择单个选项而设计的,它用于显示项目列表

如果出于某种原因确实想使用下拉列表,则需要在表单中添加隐藏的输入,然后在下拉列表项中添加
onclick
javascript甚至处理程序,因此当用户单击这些
  • 时,您可以捕获它并手动更新隐藏的输入值,以便提交