django-filter:样式选择

时间:2014-12-24 07:28:38

标签: python django django-filter

我已经创建了django-filter以便在django-table2上执行列过滤,但是我仍然无法设置生成的下拉列表的样式以匹配整个页面样式

- 我正在使用Bootsrap3

请发布任何解决此问题的建议,或者我应该使用常规django表单进行列过滤

这是我的过滤器类表单filter.py

Pi_FILTER_CHOICES= (('', 'Select PI#'),(1,"PI1"),(2,"PI2"),(3,"PI3"),)
class PI_NameFilter(filters.FilterSet):
    pi_name = filters.ChoiceFilter( label = "PI Name", choices=Pi_FILTER_CHOICES)
    class Meta:
        modle = SamplesLinkage

这是我模板上的过滤器

{% block filter %}
<form action="" method="get">
      <label for="id_pi_name">Search by PI:  </label>
      {{ filter.form.pi_name }}
      <button type="submit" class="btn btn-default btn-sm">
          <span class="glyphicon glyphicon-search" aria-hidden="true"></span> Go Find
      </button>

 </form>
 {% endblock %} 

1 个答案:

答案 0 :(得分:0)

您(或至少将来仍将面临此问题的任何人)必须使用此文档手动呈现表单字段: https://docs.djangoproject.com/en/1.11/topics/forms/#rendering-fields-manually

{{ form.non_field_errors }}
<div class="fieldWrapper">
    {{ form.subject.errors }}
    <label for="{{ form.subject.id_for_label }}">Email subject:</label>
    {{ form.subject }}
</div>
<div class="fieldWrapper">
    {{ form.message.errors }}
    <label for="{{ form.message.id_for_label }}">Your message:</label>
    {{ form.message }}
</div>
<div class="fieldWrapper">
    {{ form.sender.errors }}
    <label for="{{ form.sender.id_for_label }}">Your email address:</label>
    {{ form.sender }}
</div>
<div class="fieldWrapper">
    {{ form.cc_myself.errors }}
    <label for="{{ form.cc_myself.id_for_label }}">CC yourself?</label>
    {{ form.cc_myself }}
</div>