anyone face this issue in django?

Question:

enter image description here

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

Asked By: aruun

||

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].

Answered By: Willem Van Onsem
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.