How to use a Bootstrap 5 class (form-check) with Django 3.2.2?

818 Views Asked by At

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.

1

There are 1 best solutions below

1
On

save time and try django crispy forms