S
S
Socrates2018-01-31 10:58:29
Django
Socrates, 2018-01-31 10:58:29

How to add classes to Fields in Forms.py?

Good afternoon, tell me how to add classes to the fields when creating your form in forms.py?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Gornostaev, 2018-01-31
@Karmov69

This is detailed in the documentation :

class SomeForm(forms.ModelForm):
     class Meta:
         mode = SomeModel
         fields = ('one_field', 'another_field')
          labels = {
              'one_field': 'Метка отличающаяся от названия поля в модели',
          }
          widgets = {
              'another_field': forms.TextInput(attrs={'class': 'some-class', 'placeholder': 'Lorem ipsum'}),
          }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question