[英]Django Crispy Forms Add Div Around Submit Button
Using Django Crispy Forms I would like to add a class around my submit button like this: 使用Django Crispy Forms我想在我的提交按钮周围添加一个类,如下所示:
<div class="col-lg-offset-3 col-lg-9">
<input type="submit" value="Log Me In" class="btn btn-default" />
</div>
This is what I have managed so far: 这是我到目前为止所管理的:
<input type="submit" value="Log Me In" class="btn btn-default" />
With this code: 使用此代码:
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',)
)
As you can see I'm almost there, is there a way to include the extra divs? 你可以看到我几乎就在那里,有没有办法包括额外的div?
You need to lay out all your fields, if you want to control the wrappers: 如果要控制包装器,则需要布置所有字段:
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',
)
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.