使用Django Crispy Forms我想在我的提交按钮周围添加一个类,如下所示:
<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',)
)
你可以看到我几乎就在那里,有没有办法包括额外的div?
答案 0 :(得分: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',
)
)