Bootstrap下拉切换与django小部件 [英] Bootstrap drop down toggle with django widget

查看:111
本文介绍了Bootstrap下拉切换与django小部件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

感谢协助转换下列引导按钮/切换到Django。意思是,我想要用户从列表中选择的国家 - 在提交表单时返回。

I'd appreciate assistance in converting the following bootstrap drop down button/toggle to Django. Meaning, I want the country that a users selected from the list - to be returned when the form is submitted.

这是当前的下拉式按钮定义:

This is the current dropdown button definition :

<div class="form-group">
             <button type="submit" class="btn btn-default btn-lg"><i class="fa fa-map-marker fa-1x" style="color:blue"></i>  United States <i class="fa fa-sort"></i>
              </button> -->
  <div class="dropdown">
                <button type="button" class="btn btn-default btn-lg dropdown-toggle btn-block" id="dropdownMenu1" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> United states <span class="caret"></span>
                </button>
      <ul class="dropdown-menu columns" id="country">

         <li><a href="#">United States</a></li>
         <li><a href="#">France</a></li>
         <li><a href="#">United Kingdom </a></li>
      </ul>
   </div>
</div>


推荐答案

我最好建议使用普通的HTML表单而不是django -形成。
我适合使用HTML表单,因为它赋予我自定义我的需要。
解决方案类似于您之前提到的问题 here
所以在你的HTML模板中

I would better suggest use normal HTML form rather than django-form. I am suitable in working with HTML form as it gives power to me to customize it to my needs. And solution is similar to your earlier question here So In your HTML template

<select class="form-control" name="country>
     <option value="India">India></option>
     <option value="Germany">Germany</option>
     ....
</select>

在您的views.py

in your views.py

def someview(request):
    if request.method == "POST":
        country_name = request.POST['country']

    somemodel.objectname = countryname
    somemodel.save()

请记住在您的表单标签中使用name属性,并查看相同的内容,适用于所有html表单标签。

Remember to use name attribute in your form tag and request the same in view. It works for all html form tags.

这篇关于Bootstrap下拉切换与django小部件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆