Django Bootstrap表单字段不会调整大小

时间:2015-07-22 15:57:19

标签: django twitter-bootstrap

我正在使用bootstrap来显示我的django表单但是无法让它们调整大小。其中一个表单是文本输入区域,我希望它跨越我的大部分面板宽度。我已经尝试了多种功能但是还没有能够调整它/使输入区域更大。

html

<div class="container-fluid">
<div class="panel panel-default">
  <div class="panel-heading">
    <h4 class="text-center">
      Raw sQL Query
    </h4>
  </div>
  <form action="/InterfaceApp/table_search/" method="post" class="form">
    {% csrf_token %}
    <div class="panel-body text-center">
      {% bootstrap_form rawsQL %}
      </br> 
      <div class="container-fluid">
        <button type="submit" class="btn btn-primary center-block" value="Submit" name="rawsQL">
          {% bootstrap_icon "fire" %} Submit
        </button>
      </div>
    </div>
  </form>
</div>

表格

class TextFieldForm(forms.Form):
  def __init__(self,*args,**kwargs):
    section_label = kwargs.pop('section_label')
    initial_value = kwargs.pop('initial_value')
    required_val = kwargs.pop('required')

    super(TextFieldForm,self).__init__(*args,**kwargs)
    self.fields['text'].label=mark_safe(section_label)
    self.fields['text'].initial=initial_value
    self.fields['text'].required=required_val

  text = forms.CharField()

现在它看起来像这样:

enter image description here

任何人都可以帮助我扩大输入区域吗?

2 个答案:

答案 0 :(得分:0)

答案 1 :(得分:0)

事实证明,当你将表单传递给像{% bootstrap_form formname %}这样的django模板时,你必须进入你定义表单的位置来编辑它的外观。我通过执行以下操作修复了调整大小的问题:

<强>表格

class TextFieldForm(forms.Form):
  def __init__(self,*args,**kwargs):
    section_label = kwargs.pop('section_label')
    initial_value = kwargs.pop('initial_value')
    required_val = kwargs.pop('required')

    super(TextFieldForm,self).__init__(*args,**kwargs)
    self.fields['text'].label=mark_safe(section_label)
    self.fields['text'].initial=initial_value
    self.fields['text'].required=required_val

  text = forms.CharField(widget=forms.TextInput(attrs={'class':"form-control text-center",'placeholder':".col-md-8"}))

<强> HTML

<div class="col-md-8 centering">
   {% bootstrap_form rawsQL %}
</div>