0

I am learning Django and I want to use the form-check Bootstrap class for a checkbox but it isn't working correctly.

This is the code of my file vaccines_form.html:

{{ form.vacuna }}

This code of my file forms.py works fine:

widgets = {
    'vacuna': forms.CheckboxSelectMultiple(),
}

Vaccines

But this doesn't work well:

widgets = {
    'vacuna': forms.CheckboxSelectMultiple(attrs={'class': 'form-check'}),
}

Vaccines

I am using Django 3.2.2 with Bootstrap v5.0.0 but I am not sure if Bootstrap 5 is compatible with Django 3.2.2. Maybe I don't have to use Bootstrap classes in forms.py and use only in vaccines_form.html.

Roby Sottini
  • 2,117
  • 6
  • 48
  • 88

1 Answers1

1

save time and try django crispy forms

Ahmed Magdy
  • 101
  • 4
  • You won't have much success just a adding classes to the Django forms as the HTML layout is different as well as the CSS classes. As Ahmed said, django-crispy-forms is a solution here and there is a new Bootstrap 5 template pack. (Disclaimer, I'm the main contributor to this package) – David Smith May 31 '21 at 21:32