1

I would like to add a bootstrap class to a label of the input field of my form, I can add classes to the input field but I could not find a guide on how to add a class to the label in the form declaration, can you help me? Thanks

class MyForm(forms.Form):
file = forms.FileField (label="Choose File", widget=forms.ClearableFileInput(attrs={'multiple': True, 'class': 'custom-file-input'}))

1 Answers1

0

You can add a class to the label in your template. For example,

<form method="post" enctype="multipart/form-data" method="POST">
{% csrf_token %}
  <div class="form-group">
      <label for="{{ form.title.id_for_label }}" class="class-label">Title</label>
       {{ form.title }}
   </div>

It worked for me.

James Gantz
  • 82
  • 10