class CustomerRegistrationForm(forms.Form):
def __init__(self, *args, **kwargs):
self.helper = FormHelper()
self.helper.form_action = 'customer_register'
self.helper.layout = Layout(
HTML("""<h3>Create new customers account</h3>"""),
Row(Field('first_name',),),
Field('last_name',),
Field('gender',),
Row( Field('gender'),),
)
这个类的结果就像字段在标签下面一样,但我想有一个类似于 https://github.com/maraujop/django-crispy-forms 的例子,其中标签和字段在同一行中。
我错过了什么?
如果您使用的是默认模板包(Bootstrap),则必须将类form-horizontal
分配给表单标签。
将左对齐、右对齐的标签浮动在与控件相同的行上
要么在模板中执行此操作,要么使用form.helper
,如脆皮表单的示例要点所示:
helper.form_class = 'form-horizontal'