2016-12-21 54 views
0

我有一個Django表單是這樣的:文本框和按鈕的排列

class FriendrequestMixinForm(forms.Form): 
    email = forms.EmailField() 
    def __init__(self, *args, **kwargs): 
     self.helper = FormHelper() 
     self.helper.layout = Layout (
      Row (Div('email', css_class="col-md-6"), FormActions (Submit('submit', 'Add'), Button("cancel", "Cancel")))) 

     super(FriendrequestMixinForm, self).__init__(*args, **kwargs) 

的按鈕排列是這樣的:

Example Layout

我該如何調整的按鈕的底部電子郵件字段在一行

感謝您的幫助

回答

0

也許嘗試類似:

class FriendrequestMixinForm(forms.Form): 
    email = forms.EmailField() 
    def __init__(self, *args, **kwargs): 
     self.helper = FormHelper() 
     self.helper.form_class = "form-group" 
     self.helper.layout = Layout (
      Row(Div('email', css_class="col-md-6")), 

      FormActions(
       Submit('submit', 'Add'), 
       Button("cancel", "Cancel")    
      ) 

     ) 

     super(FriendrequestMixinForm, self).__init__(*args, **kwargs) 

編輯:更新,以使按鈕與電子郵件字段對齊,並在一排的一切。

class FriendrequestMixinForm(forms.Form): 
    email = forms.EmailField() 
    def __init__(self, *args, **kwargs): 
     self.helper = FormHelper() 
     self.helper.form_class = "form-group" 
     self.helper.layout = Layout (
      FieldWithButtons('email', 
       Submit('submit', 'Add'), 
       Button("cancel", "Cancel") 
      ), 
     ) 

     super(FriendrequestMixinForm, self).__init__(*args, **kwargs) 
+0

謝謝。這會在兩個單獨的行中生成按鈕和文本字段。我希望他們成爲一排。因爲這只是一種輔助形式。 – mbieren

+0

啊,好的,看我的編輯。 – user6731765

+0

謝謝百萬:-) – mbieren