Django form field labels are not displaying in the template
whats wrong with this code? labels are not displaying in the 'single-project.html' template. can anyone tell the mistake in this code.what should i correct it to display my labels in my template.
My forms file
class ReviewForm(ModelForm):
class Meta:
model = Review
fields = ['value', 'body']
labels = {
'value' : 'Place your vote',
'body' : 'Add a comment with your vote'
}
def __init__(self, *args, **kwargs):
super(ReviewForm, self).__init__(*args, **kwargs)
for name,field in self.fields.items():
field.widget.attrs.update({'class': 'input'})
My views file
def project(request,pk):
projectObj = Project.objects.get(id=pk)
form = ReviewForm()
return render(request,'projects/single-project.html', {'project' : projectObj, 'form':form,})
My template file
{% csrf_token %}
{% for field in form %}
<div class="form__field">
<label for="formInput#textarea">{{field.label}}</label>
{{field}}
</div>
{% endfor %}
solution to this problem