How rename input class in crispy-form Dlango

How rename input class "numberinput form-control"?

<input type="number" name="sq" step="0.1" class="numberinput form-control" required="" id="id_sq">

I can rename div class, lable class, but not input

class ProjectForm(forms.ModelForm):
    class Meta:
        model = Project
        fields = ["file", "sq", "rent_tax"]

Template

<div class="form-group col-md-6 mb-0">
  {{ form_project.sq|as_crispy_field }}
</div>

try this

Using Javascript

document.getElementById('id_sq').className = 'css-class';

in settings.py

CRISPY_CLASS_CONVERTERS = {'numberinput': "css-class"}

https://django-crispy-forms.readthedocs.io/en/latest/crispy_tag_forms.html#change-crispy-forms-input-default-classes

or

refer https://docs.djangoproject.com/en/4.1/ref/forms/fields/

class ProjectForm(forms.ModelForm):
    class Meta:
        model = Project
        fields = ["file", "sq", "rent_tax"]

    def __init__(self, *args, **kwargs):
        super(ProjectForm, self).__init__(*args, **kwargs)

        # adding html attributes
        self.fields['sq'].widget.attrs['class'] = 'css-class'
Back to Top