anyone face this issue in django?
Question:
when i created a employee form and view the form it show like as image.
<tr>
<td>{{ form.employee_name.label }}</td>
<td>{{ record.employee_name }}</td>
</tr>
<tr>
<td>{{ form.dob.label }}</td>
<td>{{ record.dob }}</td>
</tr>
<tr>
<td>{{ form.age.label }}</td>
<td>{{ form.age }}</td>
</tr>
only age field show like this, i review all my code , it didnt find and issue, if face same issue please help me
Answers:
You use {{ record.employee_name }}
here, so you don’t render the form field, you just render the value for that record
.
You thus implement this as:
<tr>
<td>{{ form.employee_name.label }}</td>
<td>{{ form.employee_name }}</td>
</tr>
<tr>
<td>{{ form.dob.label }}</td>
<td>{{ form.dob }}</td>
</tr>
<tr>
<td>{{ form.age.label }}</td>
<td>{{ form.age }}</td>
</tr>
Note: You currently don’t seem to render the errors of your form. You render the field specific ones with {{ form.dob.errors }}
and errors not specific to a field with {{ form.non_field_errors }}
. For more information, see the Rendering fields manually section of the documentation [Django-doc].
when i created a employee form and view the form it show like as image.
<tr>
<td>{{ form.employee_name.label }}</td>
<td>{{ record.employee_name }}</td>
</tr>
<tr>
<td>{{ form.dob.label }}</td>
<td>{{ record.dob }}</td>
</tr>
<tr>
<td>{{ form.age.label }}</td>
<td>{{ form.age }}</td>
</tr>
only age field show like this, i review all my code , it didnt find and issue, if face same issue please help me
You use {{ record.employee_name }}
here, so you don’t render the form field, you just render the value for that record
.
You thus implement this as:
<tr>
<td>{{ form.employee_name.label }}</td>
<td>{{ form.employee_name }}</td>
</tr>
<tr>
<td>{{ form.dob.label }}</td>
<td>{{ form.dob }}</td>
</tr>
<tr>
<td>{{ form.age.label }}</td>
<td>{{ form.age }}</td>
</tr>
Note: You currently don’t seem to render the errors of your form. You render the field specific ones with
{{ form.dob.errors }}
and errors not specific to a field with{{ form.non_field_errors }}
. For more information, see the Rendering fields manually section of the documentation [Django-doc].