[Django]-Django crispy forms โ€“ Set label text for multiple fields

13๐Ÿ‘

โœ…

Try to use the labels meta-field

Like:

class UserForm(forms.ModelForm):
    class Meta:
        model = User # Your User model
        fields = ['contact_name', 'contact_address', 'contact_email', 'contact_phone']
        labels = {
            'contact_name': 'What is your name',
        }
    helper = FormHelper()
    helper.form_method = 'POST'
    helper.add_input(Submit('Submit', 'Submit', css_class='btn-primary'))

where contact_name is the name of the field, and 'What is your name' is the output to show

๐Ÿ‘คMarco Acierno

Leave a comment