So I have a Django form and what I want is that it shows a message under (like in red) each field if they are not filled. I have tried adding the "error_messages" attribute to my widgets in each field but it won't work.
my forms.py:
class WordForm(forms.Form):
Word1 = forms.CharField(error_messages={'required': 'Please enter a word'}, required = True, label= 'Word1',
widget= forms.TextInput(attrs={
'class': "form-control is-invalid",
'placeholder': 'Enter First Word'
}))
Word2 = forms.CharField(error_messages={'required': 'Please enter a word'}, required = True, label= 'Word2',
widget= forms.TextInput(attrs={
'class': 'form-control is-invalid needs-validation was-validated',
'placeholder': 'Enter Second Word'
}))
Word3 = forms.CharField(error_messages={'required': 'Please enter a word'}, required = True, label= 'Word3',
widget= forms.TextInput(attrs={
'class': 'form-control is-invalid',
'placeholder': 'Enter Third Word'
}))
Result = forms.CharField(label= 'Result', required=False,
widget= forms.TextInput(attrs={'class': 'form-control', 'readonly': 'True'}))
my form.html:
<form method="post" class="needs-validation was-validated" novalidate>
{% csrf_token %}
<h2>Inputs</h2>
{{ form.as_p }}
</form>
As you can see, I have added the error messages field and also the is-invalid class in the widgets but It won't do anything. I don't really know if I have to create a function, cause I have seen those feedback messages but not with the form rendering. Help is much appreciated.