<hr> and spacers in a form

Hi all,

I’m writing my first advanced form using the django’s forms and bootstrap[1].

The final form shall look like this:

HEADING 1 (e.g. General Data)
Spacer (-> __________________)
Label1 Formfield1
Label2 Formfield2
Label3 Formfield3
HEADING 2 (e.g. Advanced Data)
Spacer (-> __________________)
Label4 Formfield4
Label5 Formfield5
Label6 Formfield6
HEADING 3 (e.g. Even More Advanced Data)
Spacer (-> __________________)
Label7 Formfield7
Label8 Formfield8
Label9 Formfield9

Of course I could just write a HTML template and put the labels and formfields inside. So just curious: Is there any “django-way” for headings and spacers like e.g. a simple line to seperate parts of the form from each other (on the same webpage)?


[1] Forms · Bootstrap v5.1

Hi Toni,

Django v4 has switched form rendering to use templates which may be a little more helpful to you. However, if you’re using a pre-4.0 version of Django, you’ll need to define your own templates to inject the headings and spaces as needed. Depending on your styling needs, you could use the form field to render it’s own html via

{{ form.field }}

You can get even more granular than that.. Also, in case you’re unaware there’s a popular django crispy forms package. The bootstrap v5 version created a new package: GitHub - django-crispy-forms/crispy-bootstrap5: Bootstrap5 template pack for django-crispy-forms

1 Like

A lot of helpful stuff to read. Thanks a lot!