文本字段和按钮对齐

时间:2016-12-21 15:11:53

标签: html django forms layout

我有一个像这样的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

如何将电子邮件字段底部的按钮对齐

感谢您的帮助

1 个答案:

答案 0 :(得分: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)