尝试用添加了类的div包裹我的名字和姓氏字段。
表单帮助程序本身正在工作,因为'id-exampleForm'和'blueforms'已添加到表单div中,但不会在两个字段周围生成自定义div。
# Customize Crispy forms
from crispy_forms.helper import FormHelper
from crispy_forms.layout import Layout, Fieldset, ButtonHolder, Submit, HTML, Field, Div
from django.utils.safestring import mark_safe
from crispy_forms.bootstrap import (
PrependedText, PrependedAppendedText, FormActions)
class ReservationForm(forms.Form):
first_name = forms.CharField(label='First Name', required=True)
last_name = forms.CharField(label='Last Name', required=True)
email = forms.EmailField(required=True)
def __init__(self, *args, **kwargs):
super(ReservationForm, self).__init__(*args, **kwargs)
self.helper = FormHelper()
self.helper.form_id = 'id-exampleForm'
self.helper.form_class = 'blueForms'
self.helper.layout = Layout(
#Div('first_name', style="background: white;", title="Explication title", css_class="bigdivs")
Field(
Div(
'first_name',
'last_name',
css_id = 'special-fields',
style="background: white;",
css_class="bigdivs"
),
)