2014-01-20 65 views
6

使用Django Crispy Forms我想補充一類在我的提交按鈕這樣的:Django的脆皮形式添加事業部圍繞提交按鈕

<div class="col-lg-offset-3 col-lg-9"> 
    <input type="submit" value="Log Me In" class="btn btn-default" /> 
</div> 

這是我迄今管理:

<input type="submit" value="Log Me In" class="btn btn-default" /> 

使用此代碼:

def __init__(self, host=None, *args, **kwargs): 
     super(AuthenticationForm, self).__init__(*args, **kwargs) 
     self.host = host 
     self.helper = FormHelper() 
     self.helper.form_class = 'form-horizontal' 
     self.helper.label_class = 'col-lg-3' 
     self.helper.field_class = 'col-lg-8' 
     self.helper.add_input(
      Submit('submit', 'Log Me In', css_class='btn btn-default',) 
     ) 

正如你所看到的,我幾乎在那裏,有沒有辦法將多餘的d IVS?

回答

11

你需要奠定了所有的領域,如果你想控制的包裝:

from crispy_forms.helper import FormHelper 
from crispy_forms.layout import Layout, Fieldset, ButtonHolder, Submit, Div 


class AuthenticationForm(forms.Form): 

    def __init__(self, *args, **kwargs): 
     super(AuthenticationForm, self).__init__(*args, **kwargs) 
     self.helper = FormHelper() 
     self.helper.form_class = 'form-horizontal' 
     self.helper.label_class = 'col-lg-3' 
     self.helper.field_class = 'col-lg-8' 
     self.helper.layout = Layout(
      Fieldset(
       'fieldset description text', 
       'username', 
       'password', 
      ), 
      Div(
       Submit('submit', 'Log Me In', css_class='btn btn-default'), 
       css_class='col-lg-offset-3 col-lg-9', 
      ) 
     ) 
+0

感謝明確的例子! – freb